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

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

快乐的编码。

其他回答

对于UBUNTU:如果你有一个错误的模板没有提供npx create-react-app,并且已经卸载了npm create-react-app -g,仍然不能工作,请执行以下操作:

sudo rm -rf usr/bin/create-react-app    

# this will manualy remove the create-react-app. 
npx create-react-app 

使用typescript也可以。

我已经完成了所有的步骤,但是没有帮助。

TLDR;运行NPX——ignore-existing create-react-app

我用的是Mojave 10.15.2的Mac

CRA没有全局安装-在/usr/local/lib/node_modules或/usr/local/bin中也没有找到它。

然后我看到了这条关于CRA github问题的评论。使用——ignore-existing标志运行该命令会有所帮助。

这解决了我的问题

步骤:

1.卸载create-react应用程序

npm uninstall -g create-react-app

2.现在就用

npx create-react-app my-app

这将自动为u创建模板。

如果以上这些对你都不起作用,下面就是我所做的: 在ubuntu(可能还有mac和windows)上搜索node_modules文件夹,手动删除create-react-app模块,更新包。Json和包锁。Json,然后再次运行

npx create-react-app <app-name>

作品!

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