Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm cannot find module

Tags:

node.js

npm

macos

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.

like image 480
DanielNordby Avatar asked Feb 08 '23 14:02

DanielNordby


1 Answers

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

like image 172
anj Avatar answered Feb 12 '23 10:02

anj