Maaz Zindani

Loading the index…

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

npm install finishes but there is no node_modules folder

Errornpm install finishes without an error, but the node_modules folder is missing

Short answer

npm install only creates node_modules when it has something to put there. Check three things: package.json lists dependencies, dev dependencies are not being skipped because NODE_ENV is production, and you did not use -g, which installs outside the project. Run npm config get omit to see the quickest answer.

  • 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

    Print the dependency types npm is told to leave out, and the dependencies the project asks for.

    npm config get omit
    cat package.json
  2. 2Match what you see, then jump to its fix

    1. 1package.json has no dependencies entry, or an empty one, and devDependencies is empty or missingpackage.json lists no dependenciesFix
    2. 2npm config get omit prints dev, or NODE_ENV is production in the shellOnly devDependencies exist and dev packages are omittedFix
    3. 3The command had -g or --global and the project folder stays untouchedThe install was global (-g)Fix

What does the error look like?

  • npm install finishes without an error, but the node_modules folder is missing
  • node_modules exists but is empty, or lacks the dev tools you expect

Cause 1 of 3

package.json lists no dependencies

1Check

With no arguments, npm install installs the modules listed as dependencies in package.json. An empty list means nothing is installed. Check you are in the right folder.

pwd
cat package.json

2Fix

Add what the project needs, or go to the folder that holds the real package.json.

npm install express

3Verify

node_modules now exists.

ls node_modules | head

Confirmed by docs.npmjs.com

Did this fix it?

Cause 2 of 3

Only devDependencies exist and dev packages are omitted

1Check

The omit setting defaults to dev when NODE_ENV is production. A project that has only devDependencies then gets no node_modules.

echo "$NODE_ENV"
npm config get omit

2Fix

Include dev packages for this install, or unset the variable in your shell.

npm install --include=dev
# or
unset NODE_ENV

3Verify

node_modules is created and the dev tools are in it.

ls node_modules/.bin | head

Confirmed by docs.npmjs.com

Did this fix it?

Cause 3 of 3

The install was global (-g)

1Check

With -g, packages go into {prefix}/lib/node_modules instead of the project. The prefix is shown by npm config get prefix.

npm config get prefix

2Fix

Run npm install without -g inside the project folder.

npm install

3Verify

The folder appears next to package.json.

ls -d node_modules

Confirmed by docs.npmjs.com

Did this fix it?

How do I stop it coming back?

  • Run npm install from the folder that contains package.json; check with pwd.
  • Do not export NODE_ENV=production in your own shell profile; set it in the process that runs the app.
  • Commit package-lock.json so every machine installs the same tree.

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

ng serve says it cannot determine the project or target

Cannot determine project for command.

The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.

3 causes, each with a fix

Back end

ng serve cannot find the dev-server builder package

Could not find the implementation for builder @angular/build:dev-server

The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.

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