首页 > 解决方案 > 我如何修复“npm init”并且无法升级它

问题描述

我已经 3 年没有接触过节点或编码了,有人知道如何解决这个问题吗? npm init

node:internal/modules/cjs/loader:922
  throw err;
  ^

Error: Cannot find module '../lib/cli.js'
Require stack:
- /usr/local/lib/node_modules/npm/bin/npm-cli.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:15)
    at Function.Module._load (node:internal/modules/cjs/loader:763:27)
    at Module.require (node:internal/modules/cjs/loader:991:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:2:1)
    at Module._compile (node:internal/modules/cjs/loader:1102:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1131:10)
    at Module.load (node:internal/modules/cjs/loader:967:32)
    at Function.Module._load (node:internal/modules/cjs/loader:807:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/usr/local/lib/node_modules/npm/bin/npm-cli.js' ]
}

我做了

brew upgrade node

在此之前并尝试过

brew upgrade npm

并给我

Warning: npm 15.3.0 already installed

标签: node.jsnpmhomebrew

解决方案


我通过重命名位于“/usr/local/lib”中的 node_modules 文件夹并使用 npm 附带的 nodejs.org 的安装程序重新安装 node.js 来修复它

之后我跑去rm -r noode_modules删除 node_modules 的重命名副本

不确定删除文件夹是否足够也许我应该重新安装所有旧软件包以覆盖我以前拥有的所有内容,然后将其删除以npm uninstall进行清理


推荐阅读