当我在我的终端上输入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 install -g create-react-app安装了create-react-app,我们建议你使用npm uninstall -g create-react-app来卸载这个包,以确保npx总是使用最新的版本。

这篇报道来自https://create-react-app.dev/docs/getting-started/。对我来说,这行不通。我不得不重新安装全局的create-react-app。

我解决这个问题的步骤是:

NPM卸载-g create-react-app NPM install -g create-react-app create-react-app my-app

其他回答

NPX create-react-app@latest your-project-name

在尝试了所有的答案后为我工作,希望能在未来帮助到别人。

使用该命令后:

yarn global upgrade create-react-app

然后我试着:

yarn create-react-app my-app but it didn't work for me.

不过这个方法奏效了:

npx create-react-app my-app 

这解决了我的问题

步骤:

1.卸载create-react应用程序

npm uninstall -g create-react-app

2.现在就用

npx create-react-app my-app

这将自动为u创建模板。

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

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标志运行该命令会有所帮助。

我也遇到了同样的问题,我已经在我的机器上全局安装了“创建-反应-应用程序”。 有错误:

“没有提供模板。这可能是因为您使用的是过时版本的create-react-app。 请注意,不再支持create-react-app的全球安装。”

然后我删除了以前的安装使用这个命令。

NPM卸载-g create-react-app

然后安装新的react应用程序。

create-react-app new-app