创建新的 React 应用程序时出错(“您正在运行 `create-react-app` 4.0.3,它落后于最新版本 (5.0.0)”)

New*_*ner 70 package npm reactjs create-react-app npx

即使在完成卸载部分之后,我还是一次又一次地收到此 create React app 错误。

npm uninstall -g create-react-app

最新,在 570 毫秒内审核了 1 个包

发现0个漏洞

npx create-react-app test-app

需要安装以下软件包: create-react-app 确定继续吗?(y) y

您正在运行create-react-app4.0.3,它落后于最新版本 (5.0.0)。

我们不再支持 Create React App 的全局安装。

请使用以下命令之一删除所有全局安装:

  • npm uninstall -g 创建-react-app
  • 纱线全局删除create-react-app

创建新应用程序的最新说明可以在这里找到: https ://create-react-app.dev/docs/getting-started/

C:\>npm --version
8.3.0
C:\>node --version
v16.13.0
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

adr*_*ian 173

尝试运行npx clear-npx-cache以清除 npx 缓存,然后运行该npx create-react-app your-app命令。

另请参阅有关清除缓存的答案。

此外,可能值得尝试使用以下命令强制使用最新版本:

npx create-react-app@latest my-app --use-npm


May*_*iya 21

我已通过以下步骤解决:

  1. npm uninstall -g create-react-app

  2. npx clear-npx-cache

  3. npx create-react-app myapp


Abo*_*zlR 12

解决方案 1:强制更新到最新版本

\n

只需尝试强制运行 create 命令到最新版本即可。像这样:

\n
npx create-react-app@latest_version my-app --use-npm\n
Run Code Online (Sandbox Code Playgroud)\n

最新版本5.0.0所以试试吧以下命令:

\n
npx create-react-app@5.0.0 my-app\n
Run Code Online (Sandbox Code Playgroud)\n

现在,你的错误必须得到解决。

\n

解决方案2:清除缓存

\n

你只需要清除缓存,然后就可以创建一个新的 React 项目。首先,通过运行以下命令清除缓存:

\n
npx clear-npx-cache\n
Run Code Online (Sandbox Code Playgroud)\n

如果它不起作用,请使用此方法并重试:删除此路径中的所有内容。

\n
C:\\Users\\Your_user_name\\AppData\\Roaming\\npm-cache\n
Run Code Online (Sandbox Code Playgroud)\n

在 macOS(可能还有 Linux)上,它\xe2\x80\x99s ~/.npm/_npx。您可以通过以下方式删除它:

\n
rm -rf ~/.npm/_npx\n
Run Code Online (Sandbox Code Playgroud)\n

或者尝试一下命令npm cache clean --force或者在终端中使用管理员模式现在,只需重新运行您的创建命令即可。

\n
npx create-react-app your-app\n
Run Code Online (Sandbox Code Playgroud)\n

解决方案 3:运行此命令

\n

只要一一运行这个命令就可以了。

\n
    \n
  1. npm uninstall -g create-react-app
  2. \n
  3. npm cache clean --force
  4. \n
  5. npm cache verify
  6. \n
  7. npx create-react-app my-app
  8. \n
\n