为什么我无法在 Git Bash 上运行 npm 命令?

编程入门 行业动态 更新时间:2024-10-05 15:26:29

为什么我无法在 Git Bash 上运行 npm <a href=https://www.elefans.com/category/jswz/34/1771323.html style=命令?"/>

为什么我无法在 Git Bash 上运行 npm 命令?

我使用

NodeJS
更改了
nvm
版本,现在当我尝试运行任何
npm
命令时,它会抛出错误。事件
npm -v
不起作用。这是错误:

ERROR: npm v9.6.6 is known not to run on Node.js v10.16.2. 
This version of npm supports the following node versions: `^14.17.0 || ^16.13.0 || >=18.0.0`. You can find the latest version at /.

ERROR:
C:\Users\bazha\AppData\Roaming\npm\node_modules\npm\lib\utils\exit-handler.js:19
  const hasLoadedNpm = npm?.config.loaded

npm
在 Windows 终端上完美运行,我没有收到任何错误。我想使用 Git Bash 的原因是
rm
.

我在这里尝试使用的

NodeJS
版本是
10.16.2
。我使用
nvm use 10.16.2
来更改版本。
npm
安装的
10.16.2 nodejs
版本是
6.9.0
。 Windows终端上的
node -v
10.16.2
node -v
在 Git Bash 上是
10.16.2
Windows终端上的
npm -v
6.9.0
npm -v
在 Git Bash 上抛出上面的错误

如何在 Git Bash 上运行

npm
命令?

回答如下:

错误信息为您提供确切原因:

This version of npm supports the following node versions: `^14.17.0 || ^16.13.0 || >=18.0.0`. You can find the latest version at https://nodejs/.

一共有三个版本规范,至少需要满足其中一个

1

^14.17.0
涵盖 14.17.x 版本,其中 x >= 0

2

^16.13.0
涵盖 16.13.x 版本,其中 x >= 0

3

>=18.0.0
涵盖任何高于或等于 18.0.0

的内容

你的问题

10.16.2
不符合 123 中的任何标准。报错信息也给了你解决方法:

您可以在https://nodejs/

找到最新版本

因此,您的 git bash 使用的是非常旧版本的 Node.js。你需要为你的 git bash 升级它。

更多推荐

为什么我无法在 Git Bash 上运行 npm 命令?

本文发布于:2024-05-30 20:24:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770885.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令   Git   Bash   npm

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!