npm i create-react-app
、npx create-react-app new-app
和npm init react-app new-app
安装create-react-app
,但我一直收到以下错误信息:
我该如何解决?您正在运行create-react-app 4.0.0,落后于最新版本(4.0.1)。我们不再支持全局安装Create React App。
npm i create-react-app
、npx create-react-app new-app
和npm init react-app new-app
安装create-react-app
,但我一直收到以下错误信息:
我该如何解决?您正在运行create-react-app 4.0.0,落后于最新版本(4.0.1)。我们不再支持全局安装Create React App。
npx create-react-app@latest your-project-name --use-npm
create-react-app
文档的说法,不应该全局安装create-react-app
:npm install -g create-react-app
全局安装了create-react-app
,我们建议您使用npm uninstall -g create-react-app
或yarn global remove create-react-app
卸载该包,以确保npx
始终使用最新版本。npm uninstall -g create-react-app
卸载create-react-app
。create-react-app
创建新的React应用程序时,请使用命令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@latest my-app --use-npm
我明白了
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.
所以,我只是使用了显式版本调用了这个包:
npx create-react-app@5.0.0 app-name
npm uninstall create-react-app
,因为您可能安装了非全局的版本。 - Stephen Fong在发布v4.0.2后,我也遇到了这个问题。他们提到了以下内容:
如果您之前通过
npm install -g create-react-app
全局安装了create-react-app
,我们建议您使用npm uninstall -g create-react-app
或yarn global remove create-react-app
来卸载该软件包,以确保npx
始终使用最新版本。
我按照以下步骤解决了这个问题:
卸载 create-react-app
v4.0.1:
# for npm:
npm uninstall -g create-react-app
# for yarn:
yarn global remove create-react-app
你不需要在本地目录中安装create-react-app
,所以如果你不想这样做,请跳至第3步。如果你想这样做,请使用以下命令安装v4.0.2不要使用全局标志(-g
或--global
):# for npm:
npm i create-react-app
# for yarn:
yarn add create-react-app
现在您可以使用以下命令创建新的React应用程序: 您现在可以使用以下命令创建新的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
我也遇到了同样的问题,但当我全局卸载 create-react-app
并再次全局安装后,问题得以解决。
卸载命令:
npm uninstall -g create-react-app
安装命令:
npx create-react-app my-app
如果你使用的是较旧的npm版本 (npm version < 5.2),则使用此命令:
npm install -g create-react-app
这解决了我的问题,希望它也能解决您的问题。
更新 NPX 对我有用。本页面的建议没有起到作用,但可能有所帮助。
npm update npx
npm uninstall -g create-react-app
虽然卸载命令成功运行,但它无法卸载create-react-app,所以我一遍又一遍地遇到相同的错误。
这最终对我起作用了 npx create-react-app@latest my-app --template typescript
我的做法是:
npm uninstall -g create-react-app
接下来:
npm i create-react-app # or yarn add create-react-app
我还更新了Node版本。
使用npm全局卸载create-react-app并去除全局标志后重新安装对我来说没有起作用。
npm uninstall -g create-react-app
npm install create-react-app
我原本使用的是 node 版本 15.2.0,现在通过 nvm 升级到了最新稳定版本 15.3.0。
nvm install node
然后我再次安装了create-react-app(没有使用全局标志)。
npm install create-react-app
我随后成功创建了一个新的React应用程序。
npx create-react-app my-app
编辑:以上命令将会在当前目录下安装create-react-app。需要明确的是,在全局卸载create-react-app之后,我无法再通过npx创建应用程序并收到相同的错误信息。目前我找到的最佳解决方案是运行npm install -g npm@latest
,将我的npm版本从7.0.14开发版降级到6.14.9 LTS构建,并使我能够通过npx轻松创建React应用程序。
npm install create-react-app
不会有任何作用。只需运行 npx create-react-app my-app
就可以创建一个新的 React 应用程序。 - ATYB在使用 create-react-app > 4.0.1
后,请使用以下命令:
npm init react-app my-app
yarn create react-app my-app