Npm can no longer be found in node_modules folder - node.js

I installed nvm for windows (https://github.com/coreybutler/nvm-windows) and switched to an older node version (v8.17.0). Since doing this, npm no longer works and returns:
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
module.js:550
throw err;
^
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
I checked, and indeed although the folder C:\Program Files\nodejs\node_modules\ exists, it is completely empty. So npm indeed doesn't exist in that folder. where npmreturns:
C:\Program Files\nodejs\npm
C:\Program Files\nodejs\npm.cmd
C:\Users\MyName\AppData\Roaming\npm\npm
C:\Users\MyName\AppData\Roaming\npm\npm.cmd
Here I read to run SET PATH=C:\Program Files\Nodejs;%PATH%, which I did, but that made no difference (still the same error when running npm).
I've also tried re-installing npm using the steps here, but after re-installing it, it still gives the above error.
How can I solve this?

Related

npm install and ng serve command not working despite having npm and proper path set up

I have all the required packages to run node and angular app. Everything was working fine and out of nowhere all hell broke loose. Now, when I try to run npm install to install all the dependencies of the project, I get the following issue:
$ npm install
module.js:540
throw err;
^
Error: Cannot find module 'C:\Program Files\Git\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
and when I try to create a new angular app, I get the following error:
ng new angular-app
module.js:540
throw err;
^
Error: Cannot find module 'C:\Program Files\Git\node_modules\#angular\cli\bin\ng'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
Here's my PATH env variable:
C:\ProgramData\Oracle\Java\javapath;
C:\Windows\system32;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\VG\Utils;
C:\Program Files (x86)\Lotus\Notes;
c:\oracle32\ora121\bin;
C:\Oracle64\ora121\bin;
C:\PROGRA~2\IBM\SQLLIB\BIN;
C:\PROGRA~2\IBM\SQLLIB\FUNCTION;
C:\PROGRA~2\IBM\SQLLIB\SAMPLES\REPL;
C:\PROGRA~2\ibm\gsk8\lib;
C:\Program Files\IBM\WebSphere MQ\Java\lib;
C:\Program Files (x86)\apache-maven-3.2.5\bin;
C:\Program Files (x86)\Java\jdk1.8.0\bin;
C:\Program Files\nodejs\;
C:\Program Files\Microsoft VS Code\bin;
C:\Program Files\Git\cmd;
C:\Users\UNBP\AppData\Local\Microsoft\WindowsApps;
C:\Users\UNBP\AppData\Roaming\npm
PATHEXT=.COM;
.EXE;
.BAT;
.CMD;
.VBS;
.VBE;
.JS;
.JSE;
.WSF;
.WSH;
.MSC
I have gone through all the posts here npm-cli.js not found when running npm, but that didn't solve my issue.

NPM module.js:472

When I try to start any npm command, the terminal displays
module.js:472
throw err;
^
Error: Cannot find module '/usr/lib/node_modules/npm/bin/node_modules/npm/bin/npm-cli.js'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:425:7)
at startup (bootstrap_node.js:146:9)
at bootstrap_node.js:540:3
I tried to reinstall node.js and npm.
How and where can I change the directory "usr/lib/node_modules/npm/bin/node_modules/npm/bin/npm-cli.js" to "usr/bin/node_modules/npm/bin/npm-cli.js".
p.s. When I copy all node_modules and past to /node_modules/npm/bin/, it works, but this is not an acceptable solution.
In you project folder there is a file named webpack.local.settings.js.sample. Rename the file to webpack.local.settings.js It worked for me.

'Cannot find module 'process-nextick-args' npm error after reinstalling node.js in Windows10

I downloaded Node.js (4.4.5 LTS) from the official site and installed it to update node in my Windows10, and found npm not working(node worked).I uninstalled node by installing it in "remove" mode, and then reinstalled, but the error persisted. The error upon npm -v is as follows:
```
module.js:327
throw err;
^
Error: Cannot find module 'process-nextick-args'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous>
(C:\Users\<my-name>\AppData\Roaming\npm\node_modules\np
m\node_modules\readable-stream\lib\_stream_readable.js:6:23)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
Per suggestions from [this link][2] I have edited the PATH of Environmental Variables (in both User and System) to include:
C:\Users\\AppData\Roaming\npm
and
C:\Program Files\nodejs
With 'which npm' it produced:
/c/Program Files/nodejs/npm
With 'whereis npm' it showed:
npm: /cygdrive/c/Program Files/nodejs/npm
/cygdrive/c/Program Files/nodejs/npm.cmd
With 'which node' I got
/c/Program Files/nodejs/node
```
Would appreciate any suggestions.
link2: Installing Node.js (and npm) on Windows 10
Per this link it is necessary to delete node and node_modules from 'local' directories in order to remove node (and npm) completely. Thinking I only need to remove old npm relics to solve the error about 'Error: Cannot find module 'process-nextick-args', I tried deleting npm and npm-cache inside AppData/Roaming directory manually, followed by reinstalling node in 'repair' mode, and (after restart) finally npm works.
I had this problem after a brew update. I'm using nvm so I just reconfigured nvm to use my version with nvm use vx.x.x

Node.js not searching modules in node_modules folder

I have installed packages using npm install -g http-server.
However, when i try to run this using node http-server. it throws error as below:
module.js:338
throw err;
^
Error: Cannot find module '/home/khagesh/http-server'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
I have tried setting NODE_PATH to /home/khagesh/npm/lib/node_modules.
As far as i can think is that node is not searching modules in node_modules and directly searching in user directory.
I am running it on Ubuntu 14.04.
Any help to fix this issue is appreciated.

Windows -installed node.js but npm not found

I thought npm is automatically installed with the latest node.js installer on Windows. However when I try and use npm in the command console I get the following error
C:npm install socketio
module.js:340
throw err;
^
Error: Cannot find module 'C:\Users\foo\node_modules\npm\bin\n
pm-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 checked and npm DOES exist in the nodejs Program Files directory. So is this a PATH environment issue? And if so, how do I resolve so I can use npm anywhere I open a command console window?
What version of the windows are you trying?
And also you need to check the dependencies are installed for more information check the link,
https://www.npmjs.org/package/socket.io

Resources