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

其他回答

npm WARN config global——global,——local已弃用。使用——location=global代替。需要安装以下软件包:

我正面临上述错误,所以我简单地做了这些步骤:

不要在你安装Node.js的同一个驱动器上创建一个文件夹来写命令npx create-react-app project-name 如果你在C:驱动器上安装Node.js,那么试着在另一个驱动器上创建一个文件夹来练习react 所以我把文件夹放在D:驱动器上,因为我在E:驱动器上安装Node.js 打开文件夹上的命令提示符,然后写入 NPX create-react-folder my-app命令

那么你的错误就解决了。

当我检查npm版本时,我看到这个错误:

npm -v

显示错误:

npm WARN config global——global,——local已弃用。使用——location=global代替。8.11.0

解决方案:

转到“C:\Program Files\nodejs” 打开该目录下的Visual Studio Code 打开四个文件:npm, npm。命令npx, npx. Cmd 将prefix -g修改为prefix——location=global 保存并运行npm -v

这是一个文件夹访问问题。

请遵循以下步骤:

右键单击项目文件夹 点击属性 取消选中“只读”复选框 单击Apply 然后再次尝试npm命令

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

npm install --global npm@latest

问题在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