npm install leaves devDependencies out of node_modules
Tools from devDependencies (typescript, jest, eslint) are missing after npm installShort answer
npm leaves devDependencies out when its omit list contains dev. That happens by default when NODE_ENV is production, and also when .npmrc or the command line sets omit=dev or production=true. Unset NODE_ENV, remove the setting, or pass --include=dev, and npm will install them.
Fix it fast
1Find out which cause you have
Ask npm what it will omit, then check NODE_ENV.
npm config get omit echo "NODE_ENV=$NODE_ENV"2Match what you see, then jump to its fix
- 1
npm config get omit prints dev and NODE_ENV is productionNODE_ENV is set to productionFix - 2
NODE_ENV is empty but npm config get omit still prints devAn .npmrc file sets omit=dev or production=trueFix - 3
The command in the build file contains --omit=dev or --productionA script or Dockerfile passes --omit=dev or --productionFix
- 1
What does the error look like?
Tools from devDependencies (typescript, jest, eslint) are missing after npm installpackage.json lists devDependencies but node_modules does not contain them
Cause 1 of 3
NODE_ENV is set to production
1Check
The default for omit is dev when NODE_ENV is production, and empty otherwise. Servers, Docker images and CI often export it globally.
env | grep NODE_ENV2Fix
Unset it for the install, or force dev packages in with --include=dev.
NODE_ENV=development npm install
# or
npm install --include=dev3Verify
The dev packages are on disk now.
npm ls --depth=0Confirmed by docs.npmjs.com
Cause 2 of 3
An .npmrc file sets omit=dev or production=true
1Check
npm reads the project .npmrc, then the user file and the global file. production is a deprecated alias for omit=dev, so a leftover production=true does the same thing.
cat .npmrc ~/.npmrc 2>/dev/null
npm config ls -l | grep -E "omit|production|include"2Fix
Delete the line, or add include=dev, which wins over omit if a type is in both lists.
npm config delete omit
npm config delete production3Verify
The omit list is now empty.
npm config get omit && npm installConfirmed by docs.npmjs.com
Cause 3 of 3
A script or Dockerfile passes --omit=dev or --production
1Check
Command-line flags have the highest priority, above environment variables and .npmrc.
grep -rn "omit=dev\|--production" Dockerfile package.json .github 2>/dev/null2Fix
Use the flag only in the production stage of the build. In the stage that builds or tests, install everything, then reinstall without dev packages for the final image.
# build stage
npm ci
npm run build
# runtime stage
npm ci --omit=dev3Verify
Run the build stage again and confirm the build tools exist.
npm ls --depth=0Confirmed by docs.npmjs.com
How do I stop it coming back?
- Install without NODE_ENV=production, then set it only when the app starts.
- Use --omit=dev rather than the deprecated --production flag.
- Keep build tools such as TypeScript and bundlers in devDependencies and install them in the build stage only.
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Back end
TypeScript cannot find '@angular/platform-browser' in an Angular project
Cannot find module '@angular/platform-browser' or its corresponding type declarations.
TS2307 means TypeScript could not turn the import into a file.
3 causes, each with a fixBack end
Angular build fails with TS2707 or "has no exported member" after installing a library
Module '"@angular/core"' has no exported member
These errors mean a library was compiled by a newer Angular than your app uses.
3 causes, each with a fixBack end
cdk synth says --app is required
--app is required either in command-line, in cdk.json or in ~/.cdk.json
The CDK CLI needs a command that runs your app and finds it in three places: the --app option, cdk.json in the project folder, or cdk.json in your home folder.
3 causes, each with a fixBack end
TypeScript cannot find module '@nestjs/core' or its type declarations
error TS2307: Cannot find module '@nestjs/common' or its corresponding type declarations.
TS2307 means TypeScript searched node_modules and found neither the package nor its types.
3 causes, each with a fixBack end
Mocha or Node cannot find ts-node/register
Error: Cannot find module 'ts-node/register'
Node resolves ts-node/register from your project's node_modules, so the package must be installed there, next to typescript.
2 causes, each with a fixBack end
TypeError: Class constructor cannot be invoked without 'new' in compiled TypeScript
TypeError: Class constructors cannot be invoked without 'new'
Node.js throws this when a native class is called like a plain function.
2 causes, each with a fix