node.js - 错误 : Cannot find module 'update-notifier'

标签 node.js npm npm-install

每次我在 mac 终端上运行 npm 时,我都会遇到这个错误

Mac01:~ qa$ npm
module.js:515
    throw err;
    ^

Error: Cannot find module 'update-notifier'
    at Function.Module._resolveFilename (module.js:513:15)
    at Function.Module._load (module.js:463:25)
    at Module.require (module.js:556:17)
    at require (internal/module.js:11:18)
    at /usr/local/lib/node_modules/npm/bin/npm-cli.js:29:19
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:92:3)
    at Module._compile (module.js:612:30)
    at Object.Module._extensions..js (module.js:623:10)
    at Module.load (module.js:531:32)
    at tryModuleLoad (module.js:494:12)

-> http://prntscr.com/h1r3yu

我该如何解决?

最佳答案

遇到这个问题。即使是一个简单的 npm --version 也会用同样的消息轰炸。这让我疯狂地追逐 brew 卸载、符号链接(symbolic link)错误、rm 删除文件/node_modules/npm &/node、chowning 目录——你明白了要点。不确定我的 brew 失败的根本原因,但它可能与之前作为独立安装的 npm 有关,而 Node 现在包含 npm,这导致我的机器上出现 brew config-hell。
我建议上面的提示,但如果所有其他方法都失败了,对我有用的是通过 brew 卸载,然后转到 https://nodejs.org/en/download站点并重新安装。相信我,我不想离开终端而不使用 brew,但在这种情况下,这是唯一对我有用的解决方案。

  • 通过 brew 卸载 Node :brew uninstall --ignore-dependencies nodebrew uninstall --force node
  • 转到 https://nodejs.org/en/download 下载并重新安装。
  • 现在使用 npm --version 测试错误是否消失了

关于node.js - 错误 : Cannot find module 'update-notifier' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46929153/

相关文章:

node.js - 使用 node.js、socket.io 和 redis 的一对一聊天应用程序

node.js - bookshelf.js 相当于 Rails 默认范围(在 node.js 中)

node.js - 设计模式 : Combining http requests with pluggable Redis caching mechanism

Javascript 不导入从 git 安装的 npm 包

npm - 为所有包全局设置 --no-optional 参数

node.js - 我在连接到 sqlite3 数据库时遇到错误

javascript - 如何修复 npm install React 列表过滤器

javascript - npm init给出错误:找不到模块'process-nextick-args'

node.js - 如何在安装时直接执行 'npm link'

javascript - 将外部库导入 javascript 文件