我已经在我的机器上安装了Node.js,但当我尝试运行npm install -g create-reactapp时,它会显示以下警告:

npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.

changed 67 packages, and audited 68 packages in 4s

4 packages are looking for funding
  run `npm fund` for details

2 high severity vulnerabilities

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.

当前回答

此错误是由于npm@8.11中的一个错误,该错误在8.12中已修复。

我试图使用通过NVM为Windows安装的Node.js 16.16.0,在撰写本文的时候,它安装了npm@8.11。这个bug使得不可能只是npm i -g npm@latest,所以这对我来说是有效的:

从https://libraries.io/npm/npm手动下载npm@8.13 检查Node.js的位置:nvm root(路径可能类似于C:\Users\username\AppData\Roaming\nvm) 将下载的npm解压到上面目录中的v16.16.0\node_modules(我需要解压缩两次-我使用7-Zip来做这件事)。

其他回答

只需使用以下代码:

npm install --force

这似乎解决了我的问题:

NPM install——legacy-peer-deps

我正在运行Windows 11的新安装并安装了它。

我在安装npm 8.12.1版本时遇到了类似的错误。

在Windows或IDE Visual Studio代码中的内置PowerShell终端上打开命令提示符。

在你的终端上使用这段代码将你当前的npm版本更新到最新。

NPM I -g npm@latest

它首先会显示类似于两行的相同错误消息。然后进行安装和更新;当你运行NPM -v时,更新后的NPM版本不会显示错误信息。

PS:这是在运行Windows 10 Pro的Windows机器上测试的。

不幸的是,我不能在这里评论或投票,但Md Rehan是对的。只需安装最新的npm版本:

npm i -g npm@latest

npm在> 8.13版本中修复了这个问题(我相信) 在撰写本文时,它甚至是8.19.2

我解决这个问题的方法是:

进入C:\Program Files\nodejs文件夹 你需要编辑四个文件,分别是npm和npm。命令npx, npx. Cmd 在文本编辑器中打开文件,比如Visual Studio Code 在这四个文件中,将prefix -g替换为prefix——location=global 保存全部(如果询问,保存为管理员) 准备好了!