NPM: npm-cli.js not found when running npm
Asked Answered
P

42

162

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\

Polad answered 13/7, 2014 at 10:52 Comment(4)
when you installed node?Knish
Sorry, I forgot have reinstalled node to fix this error so there's no node_modules folder now. But before that I also checked C:\Program Files\nodejs\node_modules\npm\bin\node_mod ules\ but didn't see npm folder in it.Polad
I have answer for this. Will post after 8 hours. Thanks.Polad
Well, I guess somebody may need this tip: click the node.js installer, and choose "repair", so the error was resolved.Pyrrolidine
P
157

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.

Polad answered 14/7, 2014 at 16:56 Comment(9)
Had the same problem. Never changed the path, so I am guessing that this must have happened when I upgraded Node.Cassy
I think for me the issue start to happen when I installed Electron :(Canica
where did you change this? what file?Telescope
Enviroment variables.Abramabramo
On the latest version, after upgrading, you might see both paths on your environment variables, and the old one (C:\Users\YOUR_USER\AppData\Roaming\npm) takes precedence over the new one (C:\Program Files\nodejs). Removing the former solves the issue for me.Catalogue
Yup. This worked for me. I don't know why though is NodeJS setting the path that doesn't work during installation.Gui
for me, it happend when I installed heroku-gitLubberly
If you're working with vs-code, do not forget to close every instance after having changed the path ;)Bede
In my system variable (windows) there's nothing about "C:\Program Files\nodejs\node_modules\npm\bin" I just repaired NodeJS like @3AK said and it was all goodColporteur
L
68

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.

Lick answered 26/3, 2018 at 8:59 Comment(9)
This worked for me, but it's called "apps and features" on windows 10.Kaolack
There was no npm folder in node_modules in my case and all I did was executing a command npm install express, repairing it helped.Sse
Thank you for this! my issue was resolved after repairing Nodejs under 'apps and features' on my windows pc!Intravenous
This answer should be higher up the list. Thank you!Phytohormone
Agreed. Also nice to know that feature exists in Windows 10 - so thanks to PeonProgrammer for that...Facture
This worked for me, but I could not find how to repair it from "Apps and Features." Instead, I had to open the node installer. There's a Repair button at the beginningSemiweekly
+1 because this is the closest solution to the one that fixed the issue for me. Except I am using NVM, so my solution was a sequence of nvm uninstall, nvm install and nvm use.Cannon
In my case npm removed itself every time I installed any package. Had to add npm itself in the package.json dependencies to to tell it that npm is required too and to stop it from removing itself :)Olnton
This definitely worked for two colleagues having the same issueFelecia
F
65

You need to run this in the command line.

SET PATH=C:\Program Files\Nodejs;%PATH%
Fossick answered 29/2, 2016 at 23:45 Comment(3)
bash shell in windowsFossick
I had this issue when I upgraded my version of node. Your solution worked for me perfectly. I didn't have to delete any node_modules folderTimaru
I had to move this path further up to give it higher precedence after attempting to update npm using npm (npm -i npm).Logroll
W
39

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

Warfourd answered 7/7, 2018 at 12:15 Comment(3)
Thank you, this worked great after an upgrade messed up my NPM installation and repair and reinstall didn't fix it.Monitorial
In which files we want to make this change.Please guideSwanger
Had to do something similar. Copied the nodejs folder into `C:\Users\%USERNAME%\AppData\Roaming` and renamed 'nodejs' to 'npm'. Then things started working.Outpouring
M
32

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

Misteach answered 2/7, 2015 at 19:42 Comment(1)
in the path where?Telescope
L
20

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
Langmuir answered 29/6, 2017 at 8:46 Comment(2)
If you need to set the WorkingDirectory to run the install command in a specific directory this does not solve the problemDymphia
What worked for me is to run a change directory with the npm command afterwards: "cmd.exe" /c cd /d "T:\TfsAgent_work\1\s\src\WebHost\" && "C:\Program Files\nodejs\npm.cmd" installDymphia
Z
17

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
Zebadiah answered 20/3, 2018 at 2:41 Comment(1)
Avoid this. Your node version should be in sync with npm version for better support. Even though npm will say otherwise when ran. Upgrade both together or keep the version installed together. Unless you are just testing / checking things out. Likewise with puppeteer (my upgrade related to puppeteer as well).Comber
B
15

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.

Bowlder answered 29/3, 2018 at 19:24 Comment(3)
My path looked OK; Uninstall/Reinstall resolved the issue for me.Joselyn
I had some weird issues with old node even when I switched to newer version. So I uninstalled old node and reinstalled new again. By this way I fixed the issue with cli :) thanksSkippie
Same thing, my path was OK and I'm using NVM to switch between node versions for my projects. nvm install 8.11 said it worked but for some reasons not : the node_modules directory was empty, so npm didn't worked. doing nvm uninstall 8.11 then agaon nvm install 8.11 fixed it!Lipkin
N
9

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
Nassi answered 12/4, 2016 at 9:26 Comment(0)
B
7

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.

Belamy answered 14/11, 2014 at 17:0 Comment(2)
Looks like this was fixed with newer versions of the frontend plugin: github.com/eirslett/frontend-maven-plugin/issues/147Disdainful
For me I just had to reinstall node. Thank you!Holladay
P
7

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

Pons answered 31/12, 2016 at 14:1 Comment(1)
On my system that's where global packages reside; if you remove it from the path then you may no longer be able to run gulp, etc.Classicism
T
6

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.

Tarnation answered 31/8, 2017 at 12:42 Comment(0)
H
6

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.

Hatti answered 3/1, 2018 at 11:9 Comment(0)
P
5

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

Pupil answered 11/12, 2018 at 2:20 Comment(0)
T
4

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.

Theirs answered 6/10, 2019 at 14:40 Comment(0)
P
3

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!

Purlieu answered 2/2, 2018 at 20:44 Comment(1)
Worked for me as well! Error started probably after a Win10 updateBugeye
A
3

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.

Anacreontic answered 4/3, 2018 at 20:32 Comment(0)
N
2

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.

Novella answered 27/11, 2019 at 9:6 Comment(0)
B
1

just run this command :

npm i npm@latest -g
Bensen answered 27/7, 2018 at 23:7 Comment(2)
Welcome to Stack Overflow! Could you elaborate on what this does and how it answers the question?Adduct
Avoid this. Your node version should be in sync with npm version for better support. Even though npm will say otherwise when ran. Upgrade both together or keep the version installed together. Unless you are just testing / checking things out.Comber
E
1

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

Educable answered 11/3, 2019 at 12:29 Comment(0)
L
1

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.
Landes answered 3/9, 2019 at 11:27 Comment(1)
You don't need to install Node from the official site with nvm: you can install the latest version of Node with nvm running nvm install latest.Keynes
P
1

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
Putt answered 5/12, 2020 at 5:13 Comment(2)
honestly this is such a good hack. I spent ages trying to fix what was wrong for this to workLayer
My case was very similar, but I had to copy the npm folder (which had bin and several other things) to the top level of my C driveAutorotation
H
1

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

Hesychast answered 7/5, 2022 at 9:26 Comment(0)
S
0

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

Under Tools | Options ...

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

Spinner answered 10/10, 2017 at 8:54 Comment(0)
C
0

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.

Curmudgeon answered 2/11, 2017 at 12:37 Comment(0)
H
0

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

Hephaestus answered 20/1, 2018 at 21:1 Comment(0)
H
0

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 :)

Hannus answered 25/3, 2018 at 19:42 Comment(1)
It is good to post solutions and also we appreciate this..But it wold be better if u explain logically rather than saying it Magically worked :)Superphysical
K
0

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

Kynewulf answered 3/9, 2019 at 19:12 Comment(0)
D
0

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.

Deceive answered 12/5, 2020 at 8:7 Comment(0)
S
0

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.

Stucco answered 4/11, 2020 at 15:32 Comment(0)
B
0

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

Biradial answered 4/5, 2021 at 17:40 Comment(0)
M
0

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.

Milinda answered 23/8, 2021 at 3:25 Comment(0)
H
0

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.

Hadlee answered 14/10, 2021 at 7:50 Comment(0)
M
0

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

Maxentia answered 8/3, 2022 at 12:10 Comment(0)
E
0

I tried all these solutions, but unfortunately, I keep getting the same error again and again, but I found a solution that works for me perfectly. So, I would like to share it maybe benefit someone who has the same situation as me. I discovered that the reason why I keep getting this error is that there is space in my username, so to fix the issue upgrade NVM to the latest version, which resolves the space and special character issues. by below steps:

  1. Download the latest version from here https://sourceforge.net/projects/nvm-for-windows.mirror/
  2. Complete the installation
  3. Restart your machine
Evadne answered 11/9, 2022 at 9:19 Comment(0)
W
0

I use nvm to manage my nodejs versions, so I use nvm use 12 and then it works.

Wagonlit answered 9/1, 2023 at 2:45 Comment(0)
M
0

as other answer says: the path was changed somehow

situation

  1. was downloading something using npm install (using Win10)
  2. pressed ^c to force stop it (cuz too slow)
  3. retried npm install -> error popup Error: Cannot find module 'G:\nodejs\node_modules\npm\bin\npm-cli.js'

solution

  1. find the npm-cli.js file (by using a software call Everything)
  2. discovery that the npm folder name was changed to .npm-GFyCv1zc (guess a temporary file during network download)
  3. rename that file back to npm
  4. rerun npm install -> works fine
Murderous answered 2/2, 2023 at 19:16 Comment(0)
B
0

Go to Settings > About your PC. Looking for the Advanced system settings below Related settings title.

When the window opened, choose Advandced tab > Environment Variables. In the User variables for [PC-name] box. Looking for the 'PATH' variable (create one if not existed, by clicking New...) and edit that variable's value is your nodejs folder. In my case it is 'C:\Program Files\nodejs'.

This worked for me !

Bilek answered 31/5, 2023 at 1:59 Comment(0)
T
0

To resolve on Windows

Removing the older version of NVM and installing the new version sorted the same issue on my system.

To acquire the most recent version of NVM, visit the following link: https://github.com/coreybutler/nvm-windows/releases. While writing this answer, the latest version is 1.1.12.

Once done, install the latest version of Node or whichever suits your requirement.

Tailback answered 10/1 at 4:56 Comment(0)
J
0

For me I was trying to install Node v22.0.0 and kept getting this problems, none of the solutions above worked for me. Instead I installed a lower version v20.12.2 which is LTS and it worked fine

Jenniejennifer answered 27/4 at 3:53 Comment(0)
A
-1

Updating NPM to the latest version worked for me:

npm install npm@latest -g
Apologetics answered 14/7, 2019 at 16:11 Comment(0)
S
-6

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.

Swirl answered 12/1, 2021 at 8:31 Comment(1)
The edit from @E_net4TheCurator was fine - we prefer not to add voting advice/commentary here.Habile

© 2022 - 2024 — McMap. All rights reserved.