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

知道这是怎么回事吗?


当前回答

我上周也遇到了同样的问题。我尝试了答案部分提供的许多方法。但现在情况不同了。这个create-react-app的最新版本提供了2个模板。

1. cra-template

2. cra-template-typescript

如果使用javascript,请选择cra-template。如果你使用typescript,请使用cra-template-typescript。

首先,你必须卸载create-react-app。(如果您有最新版本,请忽略此步骤。)

 npm uninstall -g create-react-app

再次安装最新版本的create-react-app

npm install create-react-app@latest

现在您必须像这样导入模板。(如果你使用typescript,请使用"cra-template-typescript"而不是"cra-template"。My-app用作名称。你可以给它起任何名字)。

npx create-react-app my-app --template cra-template

现在将下载模板。但请记住,这并不等于过去的版本。(不同的)

快乐的编码。

其他回答

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

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

But

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

我通过从全局npm lib卸载create-react-app来修复Mac上的这个问题,这基本上就是说的,只是尝试去做,你还需要做sudo:

sudo npm uninstall -g create-react-app

然后简单地运行:

npx create-react-app my-app-name

现在应该都好了,并获得如下所示的文件夹结构:

把以上的答案加起来:

随着新版本的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

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

没有人提到最基本的问题, Windows用户。 确保您更新了节点版本。 这些答案都不适合我,直到我更新了我的node.js