node.js - 我如何修复“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
解决方案
我通过重命名位于“/usr/local/lib”中的 node_modules 文件夹并使用 npm 附带的 nodejs.org 的安装程序重新安装 node.js 来修复它
之后我跑去rm -r noode_modules
删除 node_modules 的重命名副本
不确定删除文件夹是否足够也许我应该重新安装所有旧软件包以覆盖我以前拥有的所有内容,然后将其删除以npm uninstall
进行清理
推荐阅读
- sql-server - SQL Server 中的字符串操作(STRING_SPLIT,REVERSE)
- c++ - 如何从 libtorch 输出中删除乘数并显示最终结果?
- typescript - 检查赛普拉斯端点的调用
- powershell - Powershell 5.1.17763.1007 如何执行存储在变量中的字符串命令(复制项)
- apache - 301 http-to-https 重定向上没有内容安全策略
- javascript - 单击后在本地存储中按 ID 隐藏元素不起作用
- wordpress - Learnpress:未注册时检查答案和提示不起作用
- kubernetes - 是否有 kubectl 命令可以在不使用导入 yaml 文件选项的情况下创建 kafka 主题?
- elasticsearch - Logstash:elasticsearch 输出和非结构化数据
- xslt - 在 XSLT 中用子代替换父代