Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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\

like image 426
user1192476 Avatar asked Oct 16 '22 03:10

user1192476


People also ask

What is npm CLI JS?

npm is the package manager for the Node JavaScript platform. It puts modules in place so that node can find them, and manages dependency conflicts intelligently. It is extremely configurable to support a variety of use cases. Most commonly, you use it to publish, discover, install, and develop node programs.

Why is my npm not working?

If your npm is broken: On Mac or Linux, reinstall npm. Windows: If you're on Windows and you have a broken installation, the easiest thing to do is to reinstall node from the official installer (see this note about installing the latest stable version).


2 Answers

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.

like image 143
user1192476 Avatar answered Oct 22 '22 13:10

user1192476


You need to run this in the command line.

SET PATH=C:\Program Files\Nodejs;%PATH%
like image 56
Prathap Kudupu Avatar answered Oct 22 '22 13:10

Prathap Kudupu