node.js - 无法将 npm 从 6.14.8 更新到 7.3;删除 npm.cmd、npx.cmd 和 npm 会导致更多错误
问题描述
我一直在尝试使用npm install -g npm
Git Bash 中的命令全局更新我的 npm,以使其与 Angular 11 和 Node.js 版本 15.5.0 保持同步。我收到以下错误:
npm ERR! code EEXIST
npm ERR! path C:\Program Files\nodejs\npm.cmd
npm ERR! Refusing to delete C:\Program Files\nodejs\npm.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npm.cmd
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
我从中删除了文件nodejs
并尝试再次安装,但收到另一个关于npx.cmd
. 我删除了该文件,尝试安装,并收到有关 npm 文件的错误。
npm ERR! code EEXIST
npm ERR! path C:\Program Files\nodejs\npx.cmd
npm ERR! Refusing to delete C:\Program Files\nodejs\npx.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npx.cmd
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
npm ERR! code EEXIST
npm ERR! path C:\Program Files\nodejs\npm
npm ERR! Refusing to delete C:\Program Files\nodejs\npm: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npm
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
删除它们并尝试npm
再次安装后,Git Bash 不再找到 npm。安装永远不会开始。
bash: /c/Program Files/nodejs/npm: No such file or directory
我试图从我的漫游文件夹中删除 npm 文件AppData
,但收到以下错误:
npm ERR! code ENOENT
npm ERR! syscall lstat
npm ERR! path C:\Users\Yoga 2 Mitchell\AppData\Roaming\npm
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, lstat 'C:\Users\Yoga 2 Mitchell\AppData\Roaming\npm'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
我还在不同的时间尝试了以下方法:
- 删除
node_modules
并重新安装 npm - 使用 npm 7.3.0 的 Git 存储库创建一个新
npm
文件(?)(我需要再次在线查找建议以澄清/提供更多细节) - 清理缓存
- 卸载并重新安装 Angular 11 CLI 和 Node.js(针对 LTS 和当前版本进行了尝试)
到目前为止没有任何效果。我在上面列表中尝试的第二种方法能够将其更新到 6.14.10,但这种尝试返回的错误似乎会影响 Angular。为了安全起见,我将所有内容恢复到原始状态。请让我知道我是否可以澄清有关我的问题的任何其他内容。
解决方案
我就收到的错误与另一位开发人员联系。建议使用以下方法,它可以解决 LTS 的问题:如何从 Windows 中完全删除 node.js
LTS 版本允许我更新到 npm 的 6.14.11,但是当我尝试这种方法安装 Current 版本时,它仍然是 6.14.11。希望这种方法可以帮助遇到类似错误的其他人。
推荐阅读
- r - 为什么我的固定效应模型中不能包含国家虚拟变量?
- jquery-selectors - 用于父输入文本的 Jquery 选择器
- maven - SonarQube 覆盖率始终为 0
- python - 这个迭代循环如何拟合模型?(机器学习)
- python - 不明白我的宾果游戏模拟器中 TypeError 的原因
- powershell - 如何使用 PowerShell 编辑 HKCU 值
- c# - 带参数的自定义组件 Xamarin 绑定命令
- csv - 添加 csv 的第一行作为节点类型的属性 - Neo4J
- sql - 时间戳 SQL 中具有特定小时和分钟的条件
- laravel - Laravel:BroadcastWhen 等价于事件