我已经在我的机器上安装了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.12.1版本时遇到了类似的错误。
在Windows或IDE Visual Studio代码中的内置PowerShell终端上打开命令提示符。
在你的终端上使用这段代码将你当前的npm版本更新到最新。
NPM I -g npm@latest
它首先会显示类似于两行的相同错误消息。然后进行安装和更新;当你运行NPM -v时,更新后的NPM版本不会显示错误信息。
PS:这是在运行Windows 10 Pro的Windows机器上测试的。
这在Windows上是一个问题,在Windows中npm是通过npm调用的。在Node.js安装文件夹中打开cmd。
见第12行。
:: Created by npm, please don't edit manually.
@ECHO OFF
SETLOCAL
SET "NODE_EXE=%~dp0\node.exe"
IF NOT EXIST "%NODE_EXE%" (
SET "NODE_EXE=node"
)
SET "NPM_CLI_JS=%~dp0\node_modules\npm\bin\npm-cli.js"
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix -g') DO (
SET "NPM_PREFIX_NPM_CLI_JS=%%F\node_modules\npm\bin\npm-cli.js"
)
IF EXIST "%NPM_PREFIX_NPM_CLI_JS%" (
SET "NPM_CLI_JS=%NPM_PREFIX_NPM_CLI_JS%"
)
"%NODE_EXE%" "%NPM_CLI_JS%" %*
我提交了一个问题,这个警告在npm 8.12.1中得到了修复。-g不再被弃用。