npm install finishes but there is no node_modules folder
npm install finishes without an error, but the node_modules folder is missingShort 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.
Fix it fast
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.json2Match what you see, then jump to its fix
- 1
package.json has no dependencies entry, or an empty one, and devDependencies is empty or missingpackage.json lists no dependenciesFix - 2
npm config get omit prints dev, or NODE_ENV is production in the shellOnly devDependencies exist and dev packages are omittedFix - 3
The command had -g or --global and the project folder stays untouchedThe install was global (-g)Fix
- 1
What does the error look like?
npm install finishes without an error, but the node_modules folder is missingnode_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.json2Fix
Add what the project needs, or go to the folder that holds the real package.json.
npm install express3Verify
node_modules now exists.
ls node_modules | headConfirmed by docs.npmjs.com
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 omit2Fix
Include dev packages for this install, or unset the variable in your shell.
npm install --include=dev
# or
unset NODE_ENV3Verify
node_modules is created and the dev tools are in it.
ls node_modules/.bin | headConfirmed by docs.npmjs.com
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 prefix2Fix
Run npm install without -g inside the project folder.
npm install3Verify
The folder appears next to package.json.
ls -d node_modulesConfirmed by docs.npmjs.com
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 fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack 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 fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fixBack end
The command npm run build -- --prod exited with code 1 (Angular)
The command "npm run build -- --prod" exited with code 1
Exit code 1 only says the build failed; the real message is above it.
2 causes, each with a fix