Maaz Zindani

Loading the index…

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

Windows npm stops with Cannot find module ...\node_modules\npm\bin\npm-cli.js

ErrorError: 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.

  • Applies to Node.js 22, Node.js 24, Windows 11 Command Prompt
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

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

    1. 1The 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. 2The 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. 3The 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

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\nodejs

3Verify

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 -v

Confirmed by github.com

Did this fix it?

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 npm

2Fix

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 -v

Confirmed by github.com

Did this fix it?

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 -v

2Fix

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 -v

3Verify

The file exists again and npm prints its version.

dir "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js"
npm -v

Confirmed by docs.npmjs.com

Did this fix it?

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 fix

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.