NPM: npm-cli.js not found when running npm

node.jsWindowsIonic FrameworkNpmYeoman

node.js Problem Overview


Usually I can install a library using npm but today when installing yeoman I encountered this errors. Please help to figure out what's root cause.

D:\Works\phonegap\ionic\todo>npm install -g yo
    module.js:340
    throw err;
          ^
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'

at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3

I looked into the folder: > C:\Program Files\nodejs\node_modules\npm\bin\

but don't see node_modules folder as the error described.

I also try to find npm-cli.js and see it's actually in C:\Program Files\nodejs\node_modules\npm\bin\

node.js Solutions


Solution 1 - node.js

It turns out the issue is due to the wrong path of node in system variable. The path is currently pointing to

(I really don't know when I modified it)

C:\Program Files\nodejs\node_modules\npm\bin

so I change to

C:\Program Files\nodejs

and it works like a charm.

Solution 2 - node.js

You need to run this in the command line.

SET PATH=C:\Program Files\Nodejs;%PATH%

Solution 3 - node.js

I just repaired my NodeJS installation and it worked for me!

Go to Control Panel\All Control Panel Items\Programs and Features --> find NodeJS and choose option repair to repair it. Hope this helps.

Solution 4 - node.js

You may also have this problem if in your path you have C:\Program Files\nodejs and C:\Program Files\nodejs\node_modules\npm\bin. Remove the latter from the path

Solution 5 - node.js

Copy the directory named npm from your installed node path (In my case the npm directory was available in C:\Program Files\nodejs\node_modules).

Navigate to C:\Users\%USERNAME%\AppData\Roaming\npm\node_modules and paste the copied npm directory there.

This method worked for me when I had the same error. . .

Solution 6 - node.js

This not the same case as in the question, but might be helpful for someone facing the similar issue. On Windows, if you are calling npm commands from some CI/automation tool, you might run into the error:

Error: Cannot find module 'SOME_PATH\node_modules\npm\bin\npm-cli.js'

where SOME_PATH is not Program Files/... but some project directory instead. So npm tries to find npm-cli.js inside the project root directory instead of searching it in Program Files/nodejs.

The reason is npm.cmd script:

:: Created by npm, please don't edit manually.
@ECHO OFF

SETLOCAL

SET "NODE_EXE=%~dp0\node.exe"
IF NOT EXIST "%NODE_EXE%" (
  SET "NODE_EXE=node"
)


SET "NPM_CLI_JS=%~dp0\node_modules\npm\bin\npm-cli.js"
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix -g') DO (
  SET "NPM_PREFIX_NPM_CLI_JS=%%F\node_modules\npm\bin\npm-cli.js"
)
IF EXIST "%NPM_PREFIX_NPM_CLI_JS%" (
  SET "NPM_CLI_JS=%NPM_PREFIX_NPM_CLI_JS%"
)

"%NODE_EXE%" "%NPM_CLI_JS%" %*

This script uses %~dp0 to lookup the npm-cli.js but some automation tools could set work directory in the way that %~dp0 points to the local project dir so the script works incorrectly.

One possible solution could be changing the npm calls from this

npm.cmd install

to this

cmd.exe /c npm.cmd install

Solution 7 - node.js

I encountered the same problem with node 8.5 when installed with nvm. The below solution worked for me

$ nvm uninstall 8.5
8.5.0
Uninstalling node v8.5.0...Error removing node v8.5.0
Manually remove C:\Users\Omkar\AppData\Roaming\nvm\v8.5.0.

$ nvm install 8.5
8.5.0
Downloading node.js version 8.5.0 (64-bit)...
Complete
Creating C:\Users\Omkar\AppData\Roaming\nvm\temp

Downloading npm version 5.3.0... Complete
Installing npm v5.3.0...

Installation complete. If you want to use this version, type

nvm use 8.5.0

Omkar@VAST-0137 MINGW64 /d/code

This worked for me cause node 8.5 was not correctly installed before with nvm. I figured it out cause "npm\bin\npm-cli.js" folders and files were not created inside node_modules before.

Solution 8 - node.js

None of the other answers worked for me.

Here is what I write (in a git bash shell on windows ):

PATH="/c/Program Files/nodejs/:$PATH" npm run yeoman

Solution 9 - node.js

This started happening for me after I installed GoogleChrome/puppeteer, the solution was to re-install npm:

$ npm i npm@latest

or

$ npm install npm@latest

Solution 10 - node.js

On a Mac:

I was running this out of the Maven com.github.eirslett Frontend Plugin when I had the same error.

Eventually I had to:

Install Node.js via the installer download here: http://nodejs.org/

Delete all the node/ and node_modules/ folders from within my maven build structure.

Solution 11 - node.js

In addition to above I had to remove C:\Users\%USERNAME%\AppData\Roaming\npm also. This helped.

Solution 12 - node.js

Don't change any environment variables

It was the installer which caused the issue and did not install all the required file.

I just repaired the NODEJS setup on windows 7 and it works very well. May be you can reinstall, just incase something does not work.

Solution 13 - node.js

There are actually 2 paths which was added to your System's Variable when upgrading to nodejs latest version.

  1. C:\Program Files\nodejs
  2. C:\Program Files\nodejs\node_modules\npm\bin
    For windows 7/8/8.1 users, they will not have an Environment Variables Windows 10 smart GUI.
    Anyway, all you have to do is search for "C:\Program Files\nodejs\node_modules\npm\bin" and remove it.
    Also, remove "C:\Users\%USERNAME%\AppData\Roaming\npm" from your environment variables. I am posting this answer because I wasted my 10hrs searching for the solution on internet. By combining the above answer I finally make it through the problem.

Solution 14 - node.js

I had the same issue on windows. I just repaired Node and it worked fine after a restart of the command on windows.

Solution 15 - node.js

On Windows 10:

  1. Press windows key, type edit the system environment variables then enter.
  2. Click environment variables...
  3. On the lower half of the window that opened with title Environment Variables there you will see a table titled System Variables, with two columns, the first one titled variable.
  4. Find the row with variable Path and click it.
  5. Click edit which will open a window titled Edit evironment variable.
  6. Here if you find

> C:\Program Files\nodejs\node_modules\npm\bin

select it, and click edit button to your right, then edit the field to the path where you have the nodejs folder, in my case it was just shortening it to :

> C:\Program Files\nodejs

Then I closed all my cmd or powershell terminals, opened them again and npm was working.

Solution 16 - node.js

None of the solutions here worked for me but after I restarted my system and did npm install again, it worked. I would guess one or more processes I ran before held unto it.

Simple PC restart on Windows 10 did the magic for me!

Solution 17 - node.js

In my case, I was using nvm-windows 1.1.6 , and I updated my nodejs version using nvm install latest, which eventually told me that nodejs and npm are installed, however when I tried to do npm install, I received

> Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'

upon checking nvm-windows structure, I found that C:\Program Files\nodejs was symlinked to %APPDATA%\nvm\NODE_VERSION, (NODE_VERSION was v9.7.1 in my case) which has the folder node_modules having nothing inside, caused this error. The solution was to copy the npm folder from one of my previous versions' node_modules folder and paste it in. I then updated my npm with npm install npm@next -g and everything started working again.

Solution 18 - node.js

I know it is an older post but as I write this the version of Node js is 12.13.1. People face this generally because they might have already installed a previous version of Node js which added the following to the system path.

> C:\Program Files\nodejs\node_modules\npm\bin

However, the newer versions need to add the following:-

> C:\Program Files\nodejs

I mean to say the path where you installed the Nodejs. The default is

> C:\Program Files\nodejs

However, if you gave a different location you should point it to that.

Solution 19 - node.js

just run this command :

npm i npm@latest -g

Solution 20 - node.js

npm install -g npm@[version] fixed the problem

Solution 21 - node.js

For guys still coming around this thread:

  • install node from official site (check npm and node version to check whether installed properly, yes in a new terminal/cmd);
  • install nvm now and when prompt to whether manage current node with nvm click yes;
  • open new cmd and run nvm on.

Solution 22 - node.js

Solution for me in VS2017 (Under Tools | Options ... )

Under Tools | Options ...

I changed the path to: C:\Program Files\nodejs

Solution 23 - node.js

I run into this problem when installing node9.0.0 on windows7 at the end the solution was to just remove npm npm.cmd npx npx.cmd from C:\Program Files\nodejs\node_modules\npm\bin before doing this a workaround was to run C:\Program Files\nodejs\npm so that is one way so see if you have the same problem I had.

Solution 24 - node.js

create a npm folder manually inside node_modules and rerun the installer with repair options. It copies the missing files.

Solution 25 - node.js

For me none of the above worked, I just noticed that every time I do a "npm install..." any npm command just stop working. So every install I do, I have to run the NodeJS installation programme and select "repair". Until I find a real solution :)

Solution 26 - node.js

Updating NPM to the latest version worked for me:

npm install npm@latest -g

Solution 27 - node.js

Change the environment path variable C:\Program Files\nodejs\node_modules\npm\bin and open the command terminal and npm -v and

Solution 28 - node.js

I encountered the exact same problem today in a Linux server. And the reason is really simple as I didn't do make install after make and tried to directly call the generated npm. Thus the PATH and everything was a mess.

So for me, the solution is just to do make install after make and run the npm under .node/bin/npm.

Solution 29 - node.js

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'

Look at the above and it is obvious that the path has issue. 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js' SHOULD BE CHANGED TO--> 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js' which means that "\node_modules\npm\bin" in between was duplicated, which caused such a stupid error. I fixed it by editing the System Variable and updated the PATH as described above.

Solution 30 - node.js

Same Issue.

Resolved by copying the missing files from

> C:\Users\UserName\AppData\Roaming\npm\node_modules\npm\bin

to

> C:\Users\UserName\node_modules\npm\bin

The missing files are

  • npm
  • npm.cmd
  • npm-cli.js
  • npx
  • npx.cmd
  • npx-cli.js

Solution 31 - node.js

go to https://nodejs.org/dist/latest-v10.x/ and download zip file

open zip file and copy node_module\npm in C:\Users\foo\AppData\Roaming\nvm\v10.19.0\node_modules\np

Solution 32 - node.js

For anyone that would be have this problem. I can say that, in my case i discover that problem is happening when i'm running the installer from a different partition to windows was installed.

So when i reinstall using nvm-setup.exe from C: partition, all is installed an npm is finded without problems!!, no need to modify enviroment variables in my win10.

I know that this looks crazy, but i think that this can be usefull to developers resolve this issue, or anyone need help for this now.

bye.

Solution 33 - node.js

For anyone comming searching for something like Error: Cannot find module 'C:\ [Your Project Path] \node_modules\npm\bin\npm-cli.js'

Try manually removing (rightclick - delete (send to recycle bin)) the node_modules folder in your project and then run a npm ci. It can be that the problem is in fact the project was not correctly installed and then npm ci will not completely remove this, just go hardcore on it.

Solution 34 - node.js

For me worked simple delete in project folder node_modules then npm install

Solution 35 - node.js

I met the same issue before, caused by the additional npm path setting in path variable of the system Environment Variables. Just delete it, only keep the node path is enough. enter image description here

Solution 36 - node.js

I experienced this same issue when installing Node version manager (NVM) on Windows 10.

Whenever I run the command:

npm install -g yarn

I was getting the error below:

> Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'

Here's how I fixed it:

The issue was that the components of the Node installation that the Node version manager (NVM) was pointing to were not present on the computer.

So to fix this, go to https://nodejs.org/dist/ and then download the zip file of the distribution that you want. In my case it was https://nodejs.org/dist/v14.15.4/node-v14.15.4-win-x64.zip

Next, extract the zip file and copy it into the C:\Node\nvm\14.15.4\node_modules\npm directory Or the directory of your node version.

Now when you run npm install -g yarn it should run fine.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1192476View Question on Stackoverflow
Solution 1 - node.jsuser1192476View Answer on Stackoverflow
Solution 2 - node.jsPrathap KudupuView Answer on Stackoverflow
Solution 3 - node.js3AKView Answer on Stackoverflow
Solution 4 - node.jsPeter SunView Answer on Stackoverflow
Solution 5 - node.jsManojView Answer on Stackoverflow
Solution 6 - node.jsadmaxView Answer on Stackoverflow
Solution 7 - node.jsolaguView Answer on Stackoverflow
Solution 8 - node.jsedi9999View Answer on Stackoverflow
Solution 9 - node.jsmythzView Answer on Stackoverflow
Solution 10 - node.jsRedYetiView Answer on Stackoverflow
Solution 11 - node.jsRomkoView Answer on Stackoverflow
Solution 12 - node.jsTARJUView Answer on Stackoverflow
Solution 13 - node.jshaMzoxView Answer on Stackoverflow
Solution 14 - node.jsHello UniverseView Answer on Stackoverflow
Solution 15 - node.jsJulio PegueroView Answer on Stackoverflow
Solution 16 - node.jspapigeeView Answer on Stackoverflow
Solution 17 - node.jsCemalView Answer on Stackoverflow
Solution 18 - node.jsCoding the beastView Answer on Stackoverflow
Solution 19 - node.jsAissaDevLabView Answer on Stackoverflow
Solution 20 - node.jsrepoView Answer on Stackoverflow
Solution 21 - node.jsKeshav SharmaView Answer on Stackoverflow
Solution 22 - node.jsMichael MaierView Answer on Stackoverflow
Solution 23 - node.jsGriffinView Answer on Stackoverflow
Solution 24 - node.jsSaurabh NainwalView Answer on Stackoverflow
Solution 25 - node.jsOlivierView Answer on Stackoverflow
Solution 26 - node.jszyloView Answer on Stackoverflow
Solution 27 - node.jslokesh sharmaView Answer on Stackoverflow
Solution 28 - node.jsYuan TaoView Answer on Stackoverflow
Solution 29 - node.jsBenView Answer on Stackoverflow
Solution 30 - node.jsLeslie WongView Answer on Stackoverflow
Solution 31 - node.jsYoelView Answer on Stackoverflow
Solution 32 - node.jsWilliam TrigosView Answer on Stackoverflow
Solution 33 - node.jsKostas TsakalidisView Answer on Stackoverflow
Solution 34 - node.jsDima MalkoView Answer on Stackoverflow
Solution 35 - node.jsdannyView Answer on Stackoverflow
Solution 36 - node.jsPromise PrestonView Answer on Stackoverflow