当我在我的终端上输入create-react-app my-app命令时,它似乎工作了-下载所有库成功等。在该过程结束时,我得到一个消息,没有提供模板。

输入

user@users-MacBook-Pro-2 Desktop% create-react-app my-app

输出

Creating a new React app in /Users/user/Desktop/my-app.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
..... nothing out of the ordinary here .....
✨  Done in 27.28s.

A template was not provided. This is likely because you're using an outdated version of create-react-app.
Please note that global installs of create-react-app are no longer supported.

在包中。my-app的Json:

"dependencies": {
  "react": "^16.12.0",
  "react-dom": "^16.12.0",
  "react-scripts": "3.3.0" <-- up-to-date
}

我检查了CRA更改日志,它看起来像是增加了对自定义模板的支持-但是它看起来不像命令create-react-app my-app会改变。

知道这是怎么回事吗?


当前回答

我用下面的命令解决了这个问题。

NPM卸载-g create-react-app

NPM缓存清理——force

then

NPX create-react-app project_name——template all

谢谢你!对我来说也是如此。

其他回答

这是一个奇怪的问题,因为这个昨天为我工作,今天早上我遇到了同样的错误。根据发布说明,添加了一个新特性来支持模板,因此看起来命令行中的一些部分已经发生了变化(例如,——typescript被弃用而使用——template typescript)

我做到了以下几点:

卸载全局create-react-app npm npm cache校验。 关闭终端。我使用mac终端,如果使用IDE可能关闭并重新打开。 重新打开终端,浏览到你想要的项目,并通过npx使用新的模板命令约定运行create-react-app。为了让它工作,我使用了文档站点的typescript my-app来确保一致性:npx create-react-app my-app——template typescript

如果运行正常,您应该看到多个安装:一个用于react-scripts,一个用于模板。错误消息也应该不再出现。

1)

npm uninstall -g create-react-app

or

yarn global remove create-react-app

2)

似乎有一个错误,create-react-app没有正确卸载,使用其中一个新命令导致:

没有提供模板。这可能是因为您正在使用 过时版本的创建-反应-应用程序。

在使用npm uninstall -g create-react-app卸载后,检查你的命令行上是否仍然“安装”了create-react-app (Windows: where create-react-app)。如果它返回一些东西(例如/usr/local/bin/create-react-app),然后执行rm -rf /usr/local/bin/create-react-app手动删除。

3)

下面是其中一种方法:

npx create-react-app my-app
npm init react-app my-app
yarn create react-app my-app

如果以上都不行… 使用NPX clear-npx-cache 然后NPX create-react-app my-app 希望它能解决。

把以上的答案加起来:

随着新版本的create-react-app,您可以使用自定义模板创建一个新的应用程序。 目前有两个模板可用:

cra-template cra-template-typescript

用法:

npx create-react-app my-app [--template typescript]

更多关于create-react-app的最新变化:

https://github.com/facebook/create-react-app/releases/tag/v3.3.0

对于任何Windows用户仍然有这个问题,这是为我解决它:

运行create-react-app获取路径(我的路径是C:\Users\username\AppData\Local\Yarn\bin)。 导航到该目录并删除“create-react-app”和“create-react-app.cmd”。 导航到要在其中启动项目的目录。 运行npm install create-react-app, NPX create-react-app name-of-app, CD name-of-app, yarn start。

步骤4将根据您的配置而有所不同,但这只是我启动和运行的基础。