NestJS在初次安装和创建项目时,会出现错误提示 Error: Collection "@nestjs/schematics" cannot be resolved.
yarn global add @nestjs/cli
nest new project-name
Error: Collection "@nestjs/schematics" cannot be resolved.
at NodeModulesEngineHost.resolve (C:\Users\admin\AppData\Local\Yarn\Data\global\node_modules\@angular-devkit\schematics\tools\node-module-engine-host.js:75:19)
at NodeModulesEngineHost._resolveCollectionPath (C:\Users\admin\AppData\Local\Yarn\Data\global\node_modules\@angular-devkit\schematics\tools\node-module-engine-host.js:80:37)
at NodeModulesEngineHost.createCollectionDescription (C:\Users\admin\AppData\Local\Yarn\Data\global\node_modules\@angular-devkit\schematics\tools\file-system-engine-host-base.js:110:27)
at SchematicEngine._createCollectionDescription (C:\Users\admin\AppData\Local\Yarn\Data\glob at SchematicEngine.createCollection (C:\Users\admin\AppData\Local\Yarn\Data\global\node_modules\@angular-devkit\schematics\src\engine\engine.js:141:43)
at NodeWorkflow.execute (C:\Users\admin\AppData\Local\Yarn\Data\global\node_modules\@angular-devkit\schematics\src\workflow\base.js:101:41)
at main (C:\Users\admin\AppData\Local\Yarn\Data\global\node_modules\@angular-devkit\schematics-cli\bin\schematics.js:229:24)
at Object.<anonymous> (C:\Users\admin\AppData\Local\Yarn\Data\global\node_modules\@angular-devkit\schematics-cli\bin\schematics.js:336:5)
at Module._compile (internal/modules/cjs/loader.js:1076:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
Failed to execute command: node @nestjs/schematics:application --name=test1 --directory=undefined --no-dry-run --no-skip-git --package-manager=undefined --language="ts" --collection="@nestjs/schematics"
该错误为没有安装 @nestjs/schematics
继续执行安装 yarn global add @nestjs/schematics
然后再 nest new project-name 就可以了