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

知道这是怎么回事吗?


当前回答

最简单的方法之一就是使用

npx --ignore-existing create-react-app [project name]

这将删除create-react-app的旧缓存版本,然后获取新版本来创建项目。

注意:添加项目名称很重要,因为忽略现有的create-react-app版本是过时的,并且机器全局环境中的更改是临时的,因此以后仅使用npx create-react-app[项目名称]将无法提供所需的结果。

其他回答

使用命令npm uninstall -g create-react-app对我没用。

但这个方法奏效了:

Yarn全局删除create-react-app

然后:

create-react-app my-app

这个问题不是这样解决的,问题是在node的不同实例中,尝试全局删除create-react-app,然后删除node_modules和package-lock。来自根用户的Json

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

NPM uninstall -g create-react-app在某些情况下可能是一个答案,但在我的情况下不是。

您应该手动删除位于~/的create-react-app。Node /bin/或/usr/bin/(只需输入create-react-app,并使用rm -rf将其从您看到的位置删除),接下来只需运行NPM I -g create-react-app。

之后,create-react-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

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

快乐的编码。