Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

NestJS CLI says the @nestjs/schematics collection cannot be resolved

ErrorCollection "@nestjs/schematics" cannot be resolved

Short answer

The CLI looks for the schematics collection in node_modules and does not find the package. It is usually listed as a development dependency, so installs that skip dev dependencies, like NODE_ENV=production or --omit=dev, leave it out. Reinstall with dev dependencies where you run nest generate.

  • Applies to NestJS 11, npm 10, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask npm whether the package is installed in this project, and which environment settings might skip dev dependencies.

    npm ls @nestjs/schematics
    echo "NODE_ENV=$NODE_ENV"
  2. 2Match what you see, then jump to its fix

    1. 1npm ls prints (empty) or missing, and NODE_ENV is production or the install used --omit=devDev dependencies were skipped during installFix
    2. 2A fresh clone, a new CI job, or a folder moved without node_modulesnode_modules is missing or incomplete in this folderFix

What does the error look like?

  • Collection "@nestjs/schematics" cannot be resolved

Cause 1 of 2

Dev dependencies were skipped during install

1Check

npm leaves out dev dependencies when NODE_ENV is production, or when you pass --omit=dev. @nestjs/schematics is the package behind nest new, nest generate and nest upgrade, so those commands fail when it is not there.

grep -n "schematics" package.json
npm config get omit

2Fix

Install dev dependencies where you run Nest CLI commands, and keep the slim install for the final runtime image only.

npm install --include=dev
npx nest generate --help

3Verify

The package shows up and the CLI loads.

npm ls @nestjs/schematics
npx nest generate --help

Confirmed by docs.npmjs.com

Did this fix it?

Cause 2 of 2

node_modules is missing or incomplete in this folder

1Check

npm install reads package.json and installs what it lists. Until it runs in this folder, the CLI cannot find the collection.

ls node_modules/@nestjs
ls package.json

2Fix

Run the install in the project folder (the one that contains package.json), then retry the command.

npm install
npx nest generate --help

3Verify

The folder exists and the CLI loads.

ls node_modules/@nestjs/schematics

Confirmed by docs.npmjs.com

Did this fix it?

How do I stop it coming back?

  • Build in one stage with all dependencies, and copy only dist into the runtime stage.
  • Use a Node.js version the Nest docs list for the CLI generators.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

NestJS GraphQL cannot work out the output type of a field or query

Cannot determine a GraphQL output type for the "<name>". Make sure your class is decorated with an appropriate decorator.

In code-first mode Nest reads TypeScript types through decorators, and arrays, promises and unions disappear at runtime.

2 causes, each with a fix

Back end

IntelliJ IDEA breakpoints are ignored in a NestJS app

No 'Debugger listening' line appears when the NestJS app starts

IntelliJ can only debug a NestJS app when the Node.js process runs with the inspector on and the IDE attaches to its port.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.