21

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"

10 Answers 10

27

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

yarn global add @nestjs/schematics
Sign up to request clarification or add additional context in comments.

Comments

9

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

Comments

4

What worked for me was 2 lines of code -

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

Comments

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.

Comments

1

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.

Comments

1

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

Comments

1

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

Comments

1

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

and it worked for me

Comments

0

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]

Comments

-1

Install this NPM package works for me,

apollo-server-core: 3.7.0

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

1 Comment

Your answer could be improved by providing an example of the solution and how it helps the OP.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.