Reputation: 3443
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\
Upvotes: 171
Views: 452960
Reputation: 7250
If you've been through all the environment variable answers and still the "Cannot find module" dialogue shows a folder which is not present at an environment variable (and quite possible is your current working dir), try running in cmd:
where npm
This shows where it finds npm & tries to run it.
When I ran this, I realized that from mistakes on my part, I had a copy of npm.exe and npm.cmd in my current working dir. Deleted those (shouldn't been there in the first place) and it worked.
Upvotes: 0
Reputation: 253
I had issues with my existing node 16.8 installation.I had basically used the zip version since our company did not allow us to install custom software under the Program Files folder
I had 2 entries in my Environment Variables under PATH variable
As suggested in posts above I could not delete the second entry above from PATH environment varaible since I could not run 'npm -v' since the first entry folder above did not have the npm executable
I had to upgrade to node-v16.20.2 which has the npm executable file in the C:\dev\node-v16.20.2-win-x64 folder and then only needed to keep C:\dev\node-v16.20.2-win-x64 in PATH environment variable
Upvotes: 0
Reputation: 351
In my case, corporate shenanigans.
After uninstall/reinstall, worked great.
Upvotes: 3
Reputation: 34
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
Upvotes: 0
Reputation: 898
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.
Upvotes: 0
Reputation: 341
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 !
Upvotes: 0
Reputation: 1419
as other answer says: the path was changed somehow
npm install
(using Win10)^c
to force stop it (cuz too slow)npm install
-> error popup Error: Cannot find module 'G:\nodejs\node_modules\npm\bin\npm-cli.js'
npm-cli.js
file (by using a software call Everything
)npm
folder name was changed to .npm-GFyCv1zc
(guess a temporary file during network download)npm
npm install
-> works fineUpvotes: 0
Reputation: 2006
I use nvm
to manage my nodejs versions, so I use nvm use 12
and then it works.
Upvotes: 0
Reputation: 11
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:
Upvotes: 0
Reputation: 457
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.
Upvotes: 2
Reputation: 293
For me worked simple delete in project folder node_modules
then npm install
Upvotes: 0
Reputation: 29068
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.
Upvotes: -6
Reputation: 103
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.
Upvotes: 1
Reputation: 380
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.
Upvotes: 0
Reputation: 7985
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
Upvotes: 0
Reputation: 149
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
Upvotes: 1
Reputation: 199
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.
Upvotes: 0
Reputation: 467
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
.
Upvotes: 0
Reputation: 493
For guys still coming around this thread:
Upvotes: 1
Reputation: 563
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.
Upvotes: 2
Reputation: 180
On Windows 10:
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.
Upvotes: 5
Reputation: 39
Change the environment path variable C:\Program Files\nodejs\node_modules\npm\bin and open the command terminal and npm -v and
Upvotes: 0
Reputation: 518
Updating NPM to the latest version worked for me:
npm install npm@latest -g
Upvotes: 0
Reputation: 3443
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.
Upvotes: 161
Reputation: 994
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. . .
Upvotes: 52
Reputation: 3302
I had the same issue on windows. I just repaired Node and it worked fine after a restart of the command on windows.
Upvotes: 5
Reputation: 1994
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.
Upvotes: 6