npm cannot find module

2020-03-24 09:13发布

I've been all over Google and StackOverflow, viewing the various threads related to similar issues, but so far nothing has worked. My problem is that npm seems to be installing improperly...or something, I honestly have no idea: Node and npm are a dependency I use to support the Sage Wordpress theme buildout I'm working on on a different machine.

So the issue is that after uninstalling Node (to be safe), and reinstalling, Node seems to be working fine. node -v returns v5.1.0. Great. npm should be installed with it, but when I run npm -v I get the following lovely bit of error:

    $ npm
    module.js:340
        throw err;
        ^

    Error: Cannot find module 'readable-stream'
        at Function.Module._resolveFilename (module.js:338:15)
        at Function.Module._load (module.js:289:25)
        at Module.require (module.js:366:17)
        at require (module.js:385:17)
        at Object.<anonymous>                 (/Users/Daniel/.nvm/versions/node/v5.1.0/lib/node_modules/npm/node_modules/        npmlog/node_modules/are-we-there-yet/index.js:2:14)
        at Module._compile (module.js:425:26)
        at Object.Module._extensions..js (module.js:432:10)
        at Module.load (module.js:356:32)
        at Function.Module._load (module.js:313:12)
        at Module.require (module.js:366:17)

Running any npm command (even just npm) gives me this error, so as suggested in other solutions, I cannot simply run npm install readable-stream. I have also gone through various solutions (removing the node_modules folder, installing via brew, installing via brew without npm, and several others), but none seem to be working.

Any thoughts would be much appreciated.

3条回答
Juvenile、少年°
2楼-- · 2020-03-24 09:38

If you're having problems with NPM and you want to reinstall on UNIX I found this to be the easiest solution:

curl -L https://npmjs.org/install.sh | sudo sh

This will reinstall NPM and get it setup to use the latest NPM Version. This will almost always resolve any issues regarding NPM.

When the process is complete you should receive a message saying It worked.

查看更多
做自己的国王
3楼-- · 2020-03-24 09:45

You can run with command line as below:

npm install // you need remove node_modules folder, run npm install
查看更多
唯我独甜
4楼-- · 2020-03-24 09:50

I was just wrestling with this problem for half an hour (on Mac) after a failed npm update. I'm using Homebrew and I found I had to do the following:

sudo chown -Rv $USER /usr/local/lib/node_modules/ with my username

Then I reinstalled node via Homebrew:

brew uninstall node

brew install node

By this point npm was working again and I went ahead with a successful npm i -g npm

查看更多
登录 后发表回答