Tejas Suthar
Tejas Suthar

Reputation: 296

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"

Upvotes: 21

Views: 19558

Answers (10)

Amr khaled
Amr khaled

Reputation: 1

I just upgraded @nestjs/cli and @nestjs/schematics to the latest version which is :

and it worked for me

Upvotes: 0

shaunhurryup
shaunhurryup

Reputation: 1

If you have the following problem

> yarn global add @nestjs/schematics
yarn global v1.22.21
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
error @angular-devkit/[email protected]: The engine "node" is incompatible with this module. Expected version "^18.13.0 || >=20.9.0". Got "16.20.2"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/global for documentation about this command.

Try to install the same version of @nestjs/cli as the @nestjs/schematics.

I install cli using yarn global add @nestjs/[email protected] so I have to install schematics using yarn global add @nestjs/[email protected]

Upvotes: 0

Onuora Divine
Onuora Divine

Reputation: 11

I was getting the same error for mine but i was using npm instead of yarn i just updated my node version cause Nestjs uses node version of 12 and above

Upvotes: 1

Abderrahmane TAHRI JOUTI
Abderrahmane TAHRI JOUTI

Reputation: 4283

To keep using yarn, this worked for me https://github.com/nestjs/nest-cli/issues/613#issuecomment-602235328

yarn global add @nestjs/schematics

Upvotes: 26

Manikandan Ganesan
Manikandan Ganesan

Reputation: 1

Install this NPM package works for me,

apollo-server-core: 3.7.0

https://www.npmjs.com/package/apollo-server-core

Upvotes: -1

Big Smile
Big Smile

Reputation: 1124

I got the same error when creating a new nestJS project with yarn. What worked for me is doing the following:

  1. Clean yarn cache yarn cache clean
  2. Remove nest cli yarn global remove @nestjs/cli
  3. Reinstall nest cli yarn global add @nestjs/cli
  4. Create new project nest new project-name
  5. Choose yarn when 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

Upvotes: 1

Suprabhat Kumar
Suprabhat Kumar

Reputation: 685

What worked for me was 2 lines of code -

yarn add @nestjs/schematics
nest new your-project-name

Upvotes: 3

Qui-Gon Jinn
Qui-Gon Jinn

Reputation: 4388

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

Upvotes: 9

Chaos Legion
Chaos Legion

Reputation: 2970

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.

Upvotes: 1

Tejas Suthar
Tejas Suthar

Reputation: 296

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.

Upvotes: 2

Related Questions