我已经在我的机器上安装了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.

当前回答

如果您使用的是Windows系统,请以管理员身份尝试以下操作:

npm install -g npm-windows-upgrade
npm-windows-upgrade

并选择8.12.1(最新版本)进行安装。

其他回答

使用最新的npm来修复这个问题,使用给定的命令。

npm install --global npm@latest

你没有得到一个错误。这是一个警告,意味着你的命令仍然有效,但将来可能不会了。

试试这个:

npm install --location=global create-react-app

顺便说一下,你可以使用Create React App,而不用将其安装为全局依赖项。是这样的:

npx create-react-app your-project-name

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

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

它很容易打开和编辑npm。如果以管理员身份登录,则使用Visual Studio Code打开cmd文件。

右键单击npm。然后选择“用代码打开”。

该文件将在Visual Studio Code中打开。

Change prefix -g 到prefix——location=global

当你完成并尝试关闭文件时,Visual Studio Code将在右下角弹出一个消息:

保存“npm”失败。cmd `:权限不足。选择“以管理员身份重试”以管理员身份重试。

单击“以管理员身份重试”。npm。CMD文件将被保存,并且在启动时不再出现警告。

只需使用以下代码:

npm install --force