Windows npm stops with Cannot find module ...\node_modules\npm\bin\npm-cli.js
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'Short answer
npm.cmd looks for npm-cli.js in a node_modules\npm\bin folder next to itself. If the path in the error repeats that folder, Windows ran an npm.cmd from the wrong folder, usually because npm's own bin folder is on PATH. Run where npm, remove the wrong entry, and reinstall Node.js only if the file is really missing.
Fix it fast
1Find out which cause you have
Ask Windows which npm.cmd files it finds, in the order PATH reaches them. The first line is the one that runs, and its folder decides which cause below applies.
where npm node -v2Match what you see, then jump to its fix
- 1
The path in the error contains node_modules\npm\bin twice, and the first line of where npm ends in node_modules\npm\bin\npm.cmdnpm's own bin folder is on PATH, ahead of the Node.js folderFix - 2
The path in the error starts with a folder that is not the Node.js folder, such as a tools or scripts folder, and where npm lists an npm.cmd thereA copy of npm.cmd lives in a folder that has no node_modules\npm beside itFix - 3
The path in the error is the normal one, C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js, with no repeated part, and the file really is not thereThe npm folder inside the Node.js install is missing or damagedFix
- 1
What does the error look like?
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
Cause 1 of 3
npm's own bin folder is on PATH, ahead of the Node.js folder
1Check
npm.cmd builds the path to npm-cli.js from the folder it sits in: that folder plus node_modules\npm\bin\npm-cli.js. The npm package ships a copy of npm.cmd in its own bin folder. If that folder is on PATH, Windows runs that copy, and it looks for node_modules\npm\bin a second time inside the first.
where npm
echo %PATH%2Fix
Remove the entry that ends in node_modules\npm\bin from both your user and your system PATH. Keep the Node.js folder itself (for example C:\Program Files\nodejs), which holds the npm.cmd that is meant to run.
rem Entry to delete from PATH (user and system):
rem C:\Program Files\nodejs\node_modules\npm\bin
rem Entry to keep:
rem C:\Program Files\nodejs3Verify
Open a new Command Prompt, because a running window keeps the old PATH. The first npm.cmd found sits in the Node.js folder, and npm starts.
where npm
npm -vConfirmed by github.com
Cause 2 of 3
A copy of npm.cmd lives in a folder that has no node_modules\npm beside it
1Check
npm.cmd does not search for npm. By default it uses node_modules\npm\bin\npm-cli.js below its own folder (it prefers the same path under the global prefix when that file exists). An npm.cmd that was copied alone to another folder on PATH therefore fails with a path in that folder. List every npm.cmd Windows can see.
where npm2Fix
Delete the stray copy, or remove its folder from PATH, so the npm.cmd from the Node.js folder is the first one found. If you need a different location, move the whole Node.js install, not one file.
rem Delete the stray copy found by where npm (path below is only an example):
del "C:\tools\npm.cmd"3Verify
In a new Command Prompt, where npm lists the Node.js folder first and npm runs.
where npm
npm -vConfirmed by github.com
Cause 3 of 3
The npm folder inside the Node.js install is missing or damaged
1Check
Ask Windows whether the file exists. npm.cmd uses node_modules\npm\bin\npm-cli.js below its own folder, so with the folder gone there is nothing for it to start.
dir "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js"
node -v2Fix
Reinstall Node.js with the installer for the LTS version from the Node.js download page; npm is installed with it. The npm documentation recommends a Node version manager, such as nvm-windows, if you want to avoid installer problems.
rem After reinstalling, open a new Command Prompt and check both tools:
node -v
npm -v3Verify
The file exists again and npm prints its version.
dir "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js"
npm -vConfirmed by docs.npmjs.com
How do I stop it coming back?
- Never add node_modules\npm\bin to PATH; the Node.js installer already adds the one folder that npm needs.
- Do not copy npm.cmd to another folder to make it easier to reach; add the Node.js folder to PATH instead.
- Run where npm after you edit PATH or install another tool that brings its own Node.js.
- Install Node.js once, in one place, and use a version manager if you need more than one version.
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
Web apps
nvm for Windows installs but npm cannot be found
'npm' is not recognized as an internal or external command
On Windows the npm that nvm gives you only works when nvm can create its symlink and no older Node.js sits earlier in PATH.
4 causes, each with a fixBack end
npm on Windows fails because the AppData\Roaming\npm folder is missing
Error: ENOENT, stat 'C:\Users\<user>\AppData\Roaming\npm'
npm on Windows keeps global packages in the folder %AppData%\npm by default.
2 causes, each with a fixBack 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 fix