'NestJS cli error: Collection "@nestjs/schematics" cannot be resolved
I'm trying to learn NestJS and just following simple tutorial to create nestjs app.
Getting following error while executing cli command nest new test-project
NestJS cli Version: 7.1.5 NodeJS Version: v10.18.1
Error:
Error: Collection "@nestjs/schematics" cannot be resolved.
at NodeModulesEngineHost.resolve (/Users/tsuthar/.config/yarn/global/node_modules/@angular-devkit/schematics/tools/node-module-engine-host.js:74:19)
at NodeModulesEngineHost._resolveCollectionPath (/Users/tsuthar/.config/yarn/global/node_modules/@angular-devkit/schematics/tools/node-module-engine-host.js:79:37)
at NodeModulesEngineHost.createCollectionDescription (/Users/tsuthar/.config/yarn/global/node_modules/@angular-devkit/schematics/tools/file-system-engine-host-base.js:109:27)
at SchematicEngine._createCollectionDescription (/Users/tsuthar/.config/yarn/global/node_modules/@angular-devkit/schematics/src/engine/engine.js:147:40)
at SchematicEngine.createCollection (/Users/tsuthar/.config/yarn/global/node_modules/@angular-devkit/schematics/src/engine/engine.js:140:43)
at NodeWorkflow.execute (/Users/tsuthar/.config/yarn/global/node_modules/@angular-devkit/schematics/src/workflow/base.js:100:41)
at main (/Users/tsuthar/.config/yarn/global/node_modules/@angular-devkit/schematics-cli/bin/schematics.js:224:24)
at Object.<anonymous> (/Users/tsuthar/.config/yarn/global/node_modules/@angular-devkit/schematics-cli/bin/schematics.js:315:5)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
Failed to execute command: "/Users/tsuthar/.config/yarn/global/node_modules/@nestjs/cli/node_modules/.bin/schematics" @nestjs/schematics:application --name=nestjs-task-management --directory=undefined --no-dry-run --no-skip-git --package-manager=undefined --language="ts" --collection="@nestjs/schematics"
Solution 1:[1]
I had the same problem. same error message.
I installed nest with yarn so I use command bellow to add(install) shematics:
yarn global add @nestjs/schematics
If you use npm use this
npm i -g @nestjs/schematics
Solution 2:[2]
Initially, I added NestJS cli with yarn and it gave the above error. The issue gets fixed as soon as I've installed NestJS cli with Npm after removing it from yarn.
Solution 3:[3]
I faced this issure recently and none of the suggested issues worked for me. I tried using npm to install @nestjs/cli and also tried to remove @nestjs/cli and reinstall using yarn global add @nestjs/schematics.
Finally a hit and trial that did work for me to run the following command using only and only npm
npm i -g @nestjs/schematics
After this when I tried to create my project using nest new cli command, it worked like a charm. After that you're free to choose and use npm or yarn as per your convenience.
Solution 4:[4]
What worked for me was 2 lines of code -
yarn add @nestjs/schematics
nest new your-project-name
Solution 5:[5]
I got the same error when creating a new nestJS project with yarn. What worked for me is doing the following:
- Clean yarn cache
yarn cache clean - Remove nest cli
yarn global remove @nestjs/cli - Reinstall nest cli
yarn global add @nestjs/cli - Create new project
nest new project-name - Choose
yarnwhen given an option to choose package manager
As @Abderrahmane TAHRI JOUTI mentioned I followed the link and the above solution worked for me.
https://github.com/nestjs/nest-cli/issues/613#issuecomment-602235328
Solution 6:[6]
Install this NPM package works for me,
apollo-server-core: 3.7.0
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Qui-Gon Jinn |
| Solution 2 | Tejas Suthar |
| Solution 3 | Chaos Legion |
| Solution 4 | Suprabhat Kumar |
| Solution 5 | Big Smile |
| Solution 6 | Tyler2P |
