【问题标题】:npm: module.js:457 throw err; Error: Cannot find module 'npmlog' on a mac using brewnpm: module.js:457 抛出错误;错误:使用 brew 在 Mac 上找不到模块“npmlog”
【发布时间】:2017-01-23 01:20:30
【问题描述】:

我犯了错误(?)关注the instructions on the npm getting started page然后跑了

sudo npm install npm -g

现在,无论我做什么,npm 的任何执行都会导致这个错误,无论我是否以 sudo 运行它。卸载和重新安装节点没有帮​​助。

$ sudo npm

module.js:457
    throw err;
    ^

Error: Cannot find module 'npmlog'
    at Function.Module._resolveFilename (module.js:455:15)
    at Function.Module._load (module.js:403:25)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at /usr/local/lib/node_modules/npm/bin/npm-cli.js:19:13
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:75:3)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)

我在 Mac 上并使用自制软件安装了节点。

【问题讨论】:

  • 卸载时,您可能也想删除这些/usr/local/lib/node_modules/usr/local/bin/npm(我猜他们获得了错误的权限)。
  • 解决了。 --谢谢!

标签: node.js macos npm homebrew


【解决方案1】:

Alexander O'Mara 的评论帮助我解决了这个问题。解决办法:

运行 brew uninstall --ignore-dependencies node 即使有其他模块需要节点,也要强制卸载节点。

完成后,运行 brew uninstall --force node 如果有多个版本在运行,则删除计算机上的所有节点版本。

最后运行以下命令删除所有文件并重新安装节点:

rm -rf /usr/local/lib/node_modules
rm /usr/local/bin/npm
brew install node

【讨论】:

  • @Dave 你的建议也不行。您还想让我们尝试其他任何事情吗?
  • @learnningprogramming,您需要提供一些关于您的情况以及到目前为止您已经尝试过的信息。你在 OSX 上,并使用自制软件吗?当您说“您的建议也不走运”时,您还尝试过什么?
【解决方案2】:

在你的 Linux 盒子里;

您可能需要添加以下链接

  1. 转到 NPM 安装目录 > (我使用的是 NODE Current LTS 6.9.2)

  2. 在 lib/node_modules/npm/bin/npm-cli.js 中查找文件 npm-cli.js (文件名可以是cli.js或者npm-cli.js)

  3. cd ~/node-v6.9.2-linux-x64/bin

  4. mv npm npm_old

  5. 在 ~/node-v6.9.2-linux-x64/bin 中创建一个软链接 ln -s PATH-TO/npm-cli.js npm

试试 npm -v

可选 如果您需要更新 npm 版本,请执行 npm install npm@latest -g

【讨论】:

  • npm-cli.js 可以在这里找到 node-v6.9.2-linux-x64/lib/node_modules/npm/bin/npm-cli.js
  • 原来的问题是指 OSX,而​​不是 Linux。
猜你喜欢
  • 1970-01-01
  • 2018-02-26
  • 2016-04-14
  • 2016-03-04
  • 2013-09-29
  • 2018-08-06
  • 1970-01-01
  • 2018-12-30
  • 1970-01-01
相关资源
最近更新 更多