当我在我的终端上输入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会改变。

知道这是怎么回事吗?


当前回答

这是一个奇怪的问题,因为这个昨天为我工作,今天早上我遇到了同样的错误。根据发布说明,添加了一个新特性来支持模板,因此看起来命令行中的一些部分已经发生了变化(例如,——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,一个用于模板。错误消息也应该不再出现。

其他回答

对于Windows 10,我必须手动删除yarn缓存中的一些文件夹,我的路径是C:\Users\username\AppData\Local\Yarn\Cache\v1,我必须删除的文件夹是npm-create-react-app-1.0.0-1234567890abcdef

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

对于Linux,这对我来说是有效的

sudo npm uninstall -g create-react-app
npx create-react-app my-test-app

这解决了我的问题

步骤:

1.卸载create-react应用程序

npm uninstall -g create-react-app

2.现在就用

npx create-react-app my-app

这将自动为u创建模板。

我也有同样的问题。当我trid npm init react-app my-app命令返回相同的消息

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

But

Yarn create react-app my-app命令运行正常。