简体   繁体   English

npm找不到模块

[英]npm cannot find module

I've been all over Google and StackOverflow, viewing the various threads related to similar issues, but so far nothing has worked. 我一直在谷歌和StackOverflow,查看与类似问题相关的各种线程,但到目前为止没有任何工作。 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. 我的问题是,npm似乎是安装不正确...或者其他什么,我真的不知道:Node和npm是我用来支持Sage Wordpress主题构建的依赖项,我正在另一台机器上工作。

So the issue is that after uninstalling Node (to be safe), and reinstalling, Node seems to be working fine. 所以问题是在卸载Node(为了安全)并重新安装之后,Node似乎工作正常。 node -v returns v5.1.0 . node -v返回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应该随它安装,但是当我运行npm -v我得到以下可爱的错误:

    $ 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 . 运行任何npm命令(甚至只是npm )给我这个错误,所以在其他解决方案中建议,我不能简单地运行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. 我也经历了各种解决方案(删除node_modules文件夹,通过brew安装,没有npm通过brew安装,以及其他几个),但似乎都没有工作。

Any thoughts would be much appreciated. 任何想法将不胜感激。

I was just wrestling with this problem for half an hour (on Mac) after a failed npm update. 在npm更新失败后,我只是在这个问题上摔跤了半个小时(在Mac上)。 I'm using Homebrew and I found I had to do the following: 我正在使用Homebrew,我发现我必须做以下事情:

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

Then I reinstalled node via Homebrew: 然后我通过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 到目前为止, npm再次工作,我成功地进行了npm i -g npm

If you're having problems with NPM and you want to reinstall on UNIX I found this to be the easiest solution: 如果您遇到NPM问题而想要在UNIX上重新安装,我发现这是最简单的解决方案:

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

This will reinstall NPM and get it setup to use the latest NPM Version. 这将重新安装NPM并使其设置为使用最新的NPM版本。 This will almost always resolve any issues regarding NPM. 这几乎总能解决有关NPM的任何问题。

When the process is complete you should receive a message saying It worked . 当过程完成后,您应该收到一条消息,说明It worked

您可以使用命令行运行,如下所示:

npm install // you need remove node_modules folder, run npm install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM