我已经在我的机器上安装了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.
问题在8.12.1仍然存在
npm - v
npm WARN config global——global,——local已弃用。使用
——位置=全球。
8.12.1
解决方法为:
以管理员身份运行打开文件,否则无法编辑。
C:\Program Files\nodejs\npm.cmd
默认代码为:
:: 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%" %*
将上述代码替换为以下代码:
:: 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 --location=global') 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 - v
8.12.1
我也遇到了同样的问题。之前的一个回答提出了与我相同的解决方案,但它有点不清楚:
我在跑步:
节点16.16.0
NPM 8.15.0
在两个脚本中,我将:'prefix -g'替换为'prefix——location=global'。这将解决windows控制台和shell (BASH)的问题。
修复,
c: \ programfiles \ nodejs \ npm。CMD //第12行
更改前的行:
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix -g' (
更改后的行:
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix --location=global') DO (
修复,
C:\programfiles\nodejs\npm //第23行
更改前的行:
NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
更改后的行:
NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix --location=global`
这些更改处理了每次调用npm时得到的警告。希望这澄清和帮助!
这是在Windows 11 Pro, Windows 10 Pro, Ubuntu 20.04.4 LTS (GNU/Linux 5.10.102.1-microsoft-standard-WSL2 x86_64)上测试的。
我使用以下shell:
GitBash
PowerShell
cmd
Ubunto (WSL)
希望这能把事情弄清楚!