Maaz Zindani

Loading the index…

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

npm install leaves devDependencies out of node_modules

ErrorTools from devDependencies (typescript, jest, eslint) are missing after npm install

Short 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.

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

Fix it fast

  1. 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"
  2. 2Match what you see, then jump to its fix

    1. 1npm config get omit prints dev and NODE_ENV is productionNODE_ENV is set to productionFix
    2. 2NODE_ENV is empty but npm config get omit still prints devAn .npmrc file sets omit=dev or production=trueFix
    3. 3The command in the build file contains --omit=dev or --productionA script or Dockerfile passes --omit=dev or --productionFix

What does the error look like?

  • Tools from devDependencies (typescript, jest, eslint) are missing after npm install
  • package.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_ENV

2Fix

Unset it for the install, or force dev packages in with --include=dev.

NODE_ENV=development npm install
# or
npm install --include=dev

3Verify

The dev packages are on disk now.

npm ls --depth=0

Confirmed by docs.npmjs.com

Did this fix it?

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 production

3Verify

The omit list is now empty.

npm config get omit && npm install

Confirmed by docs.npmjs.com

Did this fix it?

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/null

2Fix

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=dev

3Verify

Run the build stage again and confirm the build tools exist.

npm ls --depth=0

Confirmed by docs.npmjs.com

Did this fix it?

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:

Related fixes

Back 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 fix

Back 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 fix

Next step

Want this handled for good?

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