修复错误:You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.0)

451 阅读2分钟

今天,当我在创建react应用程序时,它得到了一个错误:

You are running create-react-app 4.0.3, which is behind the latest release (5.0.0). We no longer support the global installation of Create React App.

修复运行create-react-app 4.0.3,它落后于最新版本(5.0.0)

在我的系统中,我用下面的命令创建了一个反应式应用程序

A:\work>npx create-react-app kend-react-examples
Need to install the following packages:
  create-react-app
Ok to proceed? (y) y

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

We no longer support the 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/

React应用程序没有被创建,相反,它抛出了一个错误。

在我的系统中,有两个版本的本地create-react-app安装和npx create-react-app不匹配。

它建议删除全局安装

我尝试用下面的命令来卸载

npm uninstall -g create-react-app

再次,创建了一个应用程序,得到了同样的错误。

uninstall globally命令并没有单独解决我的问题。

那么,你是如何解决这些问题的?

有多种方法来解决这个问题。

第一种方法,清除npx全局缓存,获得最新的软件包并运行

npm uninstall -g create-react-app
npx clear-npx-cache
npx create-react-app kendo-react-app

上面的命令可以

  • 全局卸载create-react-app CLI
  • npx清除缓存
  • 创建一个反应应用

通过上述步骤,它是有效的,如果它不工作,尝试下面提到的第二种方法。

另一种方法是用最新的软件包运行npx,使用强制选项。

npx create-react-app@latest kendo-react-appp --use-npm

现在,创建反应应用程序,它的工作原理如下所示

A:\work>npx create-react-app kend-react-examples
Need to install the following packages:
  create-react-app
Ok to proceed? (y) y
npm, WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.

Creating a new React app in A:\work\kend-react-examples.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...


added 1370 packages in 5m

169 packages are looking for funding
  run `npm fund` for details

Initialized a git repository.

Installing template dependencies using npm...
npm WARN deprecated source-map-resolve@0.6.0: See https://github.com/lydell/source-map-resolve#deprecated

added 38 packages in 24s

169 packages are looking for funding
  run `npm fund` for details
Removing template package using npm...


removed 1 package, and audited 1408 packages in 10s

169 packages are looking for funding
  run `npm fund` for details

8 moderate severity vulnerabilities

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.

Created git commit.

Success! Created kend-react-examples at A:\work\kend-react-examples
Inside that directory, you can run several commands:

  npm start
    Starts the development server.

  npm run build
    Bundles the app into static files for production.

  npm test
    Starts the test runner.

  npm run eject
    Removes this tool and copies build dependencies, configuration files
    , and scripts into the app directory. If you do this, you can’t go back!

We suggest that you begin by typing:

  cd kend-react-examples
  npm start

Happy hacking!

结语

作为总结,学会了如何解决一个错误You are running create-react-app 4.0.3, which is behind the latest release (5.0.0)