create-react-app 自 4.0.1 版起不起作用

Sum*_*gde 64 npm reactjs npm-install create-react-app npx

我尝试create-react-app使用npm i create-react-app,npx create-react-app new-app和安装npm init react-app new-app,但我不断收到此错误消息:

You are running create-react-app 4.0.0, which is behind the latest release (4.0.1).
We no longer support global installation of Create React App.
Run Code Online (Sandbox Code Playgroud)

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

Ary*_*hur 79

所有现有答案都不正确。

根据该create-react-app文件create-react-app应该不会在全球范围内安装:

如果您之前已create-react-app通过 全局安装npm install -g create-react-app,我们建议您使用npm uninstall -g create-react-app或卸载软件包yarn global remove create-react-app以确保npx始终使用最新版本。

这甚至在您收到的错误消息中说明:

您正在运行 create-react-app 4.0.0,它落后于最新版本 (4.0.1)。 我们不再支持全局安装 Create React App。

(强调我的)


您必须create-react-app使用npm uninstall -g create-react-app.

然后每次你想用 来创建一个新的 React 应用程序时create-react-app,使用命令npx create-react-app my-app

因此,要修复您遇到的错误,请create-react-app全局卸载、更新 npm、清除缓存,然后重试创建应用程序。

在你的终端中运行这个:

npm uninstall -g create-react-app && npm i -g npm@latest && npm cache clean -f && npx create-react-app my-app
Run Code Online (Sandbox Code Playgroud)

  • 我没有在全球范围内安装它,但收到此消息 (24认同)
  • @Sean256嗨,尝试使用`npm i -g npm@latest`更新npm,然后使用[nvm](https://github.com/nvm-sh/nvm/blob/master/README.md)如果你在MacOS/Linux 或 [nvmw](https://github.com/coreybutler/nvm-windows/blob/master/README.md)(如果您在 Windows 上)更新 Node.js,然后重试 (12认同)
  • 按照@ΛryΛn的建议运行“npm i -g npm@latest”对我有用! (11认同)
  • NPM 一如既往的垃圾。谢谢! (8认同)
  • “清除缓存”是我缺少的重要部分,谢谢 (7认同)
  • 对我来说 npm uninstall -g create-react-app && npm i -g npm@latest && sudo npm cache clean -f 解决了获取错误消息的问题 (2认同)

MeV*_*mar 53

这对我有用:

npx create-react-app@latest your-project-name --use-npm
Run Code Online (Sandbox Code Playgroud)


Eli*_*hen 34

我有

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.
Run Code Online (Sandbox Code Playgroud)

所以我只是用显式版本调用该包:

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


小智 14

他们发布 v4.0.2 后我也遇到了这个问题。

他们提到了这一点:

如果您之前已create-react-app通过 全局安装npm install -g create-react-app,我们建议您使用npm uninstall -g create-react-app或卸载软件包yarn global remove create-react-app以确保npx始终使用最新版本。

我按照以下步骤解决了这个问题:

  1. 卸载create-react-appv4.0.1:

    # for npm:
    npm uninstall -g create-react-app
    
    # for yarn:
    yarn global remove create-react-app
    
    Run Code Online (Sandbox Code Playgroud)
  2. 您不需要安装create-react-app在本地目录中,因此如果您不想这样做,请转到第 3 步。如果您想这样做,请使用以下命令安装 v4.0.2,而不使用全局标志 (-g--global):

    # for npm:
    npm i create-react-app
    
    # for yarn:
    yarn add create-react-app
    
    Run Code Online (Sandbox Code Playgroud)
  3. 您现在可以使用以下命令创建一个新的 React 应用程序:

    # for npx:
    npx create-react-app my-app
    
    # for npm:
    npm init react-app my-app
    
    # for yarn:
    yarn create react-app my-app
    
    Run Code Online (Sandbox Code Playgroud)


co_*_*ssm 12

我也面临同样的问题,但是当我create-react-app全局卸载然后再次全局安装时问题得到解决。

卸载命令:

npm uninstall -g create-react-app

安装命令:

npx create-react-app my-app

如果您有旧的 npm 版本(npm 版本 < 5.2),请使用以下命令:

npm install -g create-react-app

它解决了我的问题,希望它能解决你的问题

  • 这个答案是不正确的:[`create-react-app` 不应该**全局安装](/sf/answers/4553052731/) (4认同)
  • @co_ssm 它可能有效,但不再支持全局安装`create-react-app`,并且会在以后的项目中给您带来一些问题。您应该使用“npx create-react-app my-app”创建一个新应用程序,请检查我的答案以获取更多信息 (2认同)

roo*_*der 9

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

虽然卸载命令成功运行,但无法卸载 create-react-app,所以我一次又一次遇到相同的错误

这终于对我有用了npx create-react-app@latest my-app --template typescript


小智 8

对我有用的是:

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

进而:

npm i create-react-app # or yarn add create-react-app
Run Code Online (Sandbox Code Playgroud)

我还更新了 Node 版本。


Ani*_*dey 6

create-react-app > 4.0.1使用这些命令后

新项目管理

npm init react-app my-app
Run Code Online (Sandbox Code Playgroud)

yarn create react-app my-app
Run Code Online (Sandbox Code Playgroud)

开始使用 | 创建 React 应用程序文档


Ale*_*all 5

通过 npm 全局卸载 create-react-app 并在没有全局标志的情况下重新安装对我不起作用。

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

我在节点版本 15.2.0 上。我通过 nvm 升级到最新的稳定节点版本 15.3.0。

nvm install node
Run Code Online (Sandbox Code Playgroud)

然后我再次安装了 create-react-app(没有全局标志)。

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

然后我能够成功创建一个新的反应应用程序。

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

编辑:以上将安装 create-react-app 到您的当前目录。需要明确的是,在全局卸载 create-react-app 后,我无法再通过 npx 创建应用程序并收到相同的原始错误消息。到目前为止,我发现的最佳解决方案是运行npm install -g npm@latest将我的 npm 版本从 7.0.14 dev build 降级到 6.14.9 LTS build,并允许我通过 npx 创建反应应用程序而没有问题。


Bre*_*t25 5

我安装了 nvm,并在使用命令时npx create-react-app my-app;我收到这个错误:

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

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
Run Code Online (Sandbox Code Playgroud)

我确认我的 nvm 全局目录中没有全局安装 create-react-app 。

我通过指定包的版本解决了问题

npx create-react-app@4.0.2 my-app
Run Code Online (Sandbox Code Playgroud)


kob*_*003 5

对我来说,这是我的 npm 版本的问题。所以我这样做了:

npm install npm@latest -g
Run Code Online (Sandbox Code Playgroud)

现在npx create-react-app app_name可以了。


小智 5

更新 NPX 对我有用。此页面上的建议没有起到作用,但可能有所贡献。

npm update npx
Run Code Online (Sandbox Code Playgroud)

  • 这是唯一对我有用的东西!令人惊讶的是,只需更新/重新安装软件包就可以解决许多错误。 (2认同)

Chr*_*ris 0

我通过以下方式解决了这个问题:

  1. 使用 home-brew 通过终端卸载节点。

  2. 确保使用以下命令进行深度清理:

     brew uninstall node; 
     brew cleanup;
     brew uninstall --force node
    
    Run Code Online (Sandbox Code Playgroud)
  3. 前往node.js下载链接,下载稳定版包并安装。现在应该可以了。