我已经在我的机器上安装了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来修复这个问题,使用给定的命令。

npm install --global npm@latest

其他回答

在Windows上升级npm需要手动步骤,以确保PowerShell/CMD找到新版本的npm

对于Windows用户(感谢Lars)使用这个库:

以管理员身份打开PowerShell并运行(策略信息):

Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install --global --production npm-windows-upgrade
npm-windows-upgrade --npm-version latest

记得回到最初的策略:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force

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

npm i -g npm@latest

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

这似乎解决了我的问题:

NPM install——legacy-peer-deps

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

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

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

只需使用以下代码:

npm install --force