npx create-react-app 提示全局卸载不存在的 create-react-app 包?

For*_*lor 51 typescript reactjs yarnpkg npx

我在涉及全局安装的 npx create-react-app 方面遇到问题。我感到困惑,因为据我所知,我的机器上没有安装 create-react-app 包。

一些细节:

我启动了一个反应项目(使用打字稿模板),就像我之前和最近在同一台机器上多次完成的那样:

npx create-react-app --template typescript .

我从终端收到此提示

Need to install the following packages: create-react-app Ok to proceed? (y)

我按 y 确认可以继续。(如果我按 n,进程将终止并出现以下错误:npm ERR! canceled。)然后终端显示以下消息

You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.0).

We no longer support global installation of Create React App.

Please remove any global installs with one of the following commands:
- npm uninstall -g create-react-app
- yarn global remove create-react-app

The latest instructions for creating a new app can be found here:
https://create-react-app.dev/docs/getting-started/
Run Code Online (Sandbox Code Playgroud)

我运行两个建议的命令来全局卸载 create-react-app 。npm 顺利进行:


npm uninstall -g create-react-app

up to date, audited 1 package in 179ms

found 0 vulnerabilities
Run Code Online (Sandbox Code Playgroud)

全局纱线卸载结果显示以下消息:

remove create-react-app
yarn global v1.22.17
warning package.json: No license field
[1/2]   Removing module create-react-app...
error This module isn't specified in a package.json file.
info Visit https://yarnpkg.com/en/docs/cli/global for documentation about this command.

Run Code Online (Sandbox Code Playgroud)

最后,我尝试查找我的机器上是否存在 create-react-app , which create-react-app 结果是 create-react-app not found.

我不知道还有什么办法可以解决这个问题。

编辑:Deepthi 和 Sators 提供的解决方案。我必须使用命令清除存储旧版本 create-react-app 的 npx 缓存:

npx clear-npx-cache

小智 102

对于遇到类似情况:“您正在运行create-react-app4.0.3,它落后于最新版本 (5.0.0)。”

解决方案是:

>  npx clear-npx-cache
Run Code Online (Sandbox Code Playgroud)

然后做:

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

  • 谢谢你!我尝试了从清除 npm 缓存到卸载并重新安装节点的所有方法,最后这个解决方案修复了它:) (7认同)
  • 谢谢!该命令解决了我的问题。 (4认同)
  • 这确实有效!请勾选此答案 (3认同)

Sat*_*ors 31

您可以尝试通过运行以下命令来查找已安装的版本:

npm ls -g create-react-app
Run Code Online (Sandbox Code Playgroud)

您可能还想考虑阅读这篇文章,通过使用以下方法删除/清除 npx 缓存:

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

最后,另一个选择是通过运行以下命令来确保您使用的是最新版本的 create-react-app:

npx create-react-app@latest --template typescript .
Run Code Online (Sandbox Code Playgroud)

  • 清除 npx 缓存对我来说很有效。我再次进入快乐的黑客领域,非常感谢! (2认同)

San*_*ash 12

这里的问题是 npx create-react-app 正在尝试安装旧版本 (4.0.3) 的软件包,而最新版本是 (5.0.0)。

您可以使用以下命令简单地清除 npx 缓存:

npx clear-npx-cache

然后尝试使用再次创建一个反应应用程序

npx create-react-app Your_project_name

或者

您可以将 npx 与 @latest 一起使用,以保证您正在运行 create-react-app 以及最新版本:

npx create-react-app@latest Your_project_name

或者

您可以使用以下命令在工作目录中本地安装最新的 React 应用程序模块:

npm install create-react-app@latest

(这将在工作目录中创建除了package.json和package-lock.json之外的react模块,安装react应用程序时将依赖这些模块,因此您可以在完成下一步后删除它们)

进而:

npx create-react-app Your_project_name

  • 谢谢@sanad-khamash。`npx create-react-app@latest` 为我工作,确保我正在运行 `create-react-app` 最新版本。 (2认同)

小智 8

显然该版本有问题,我也有同样的问题,但是使用命令

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

它成功了,然后我就运行了

npx create-react-app proyect-name
Run Code Online (Sandbox Code Playgroud)

它有效!

我认为这与上面的答案相同,但是好吧,就这样吧。


归档时间:

查看次数:

15014 次

最近记录:

2 年,7 月 前