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

知道这是怎么回事吗?


当前回答

如果你得到这个错误'Template not provided ...."一遍又一遍,然后直接执行以下步骤:

NPM卸载-g create-react-app 使用命令"which create-react-app"查看文件" create-react-app"的位置 现在手动删除该文件,使用命令“rm -rf /usr/local/bin/create-react-app”将此命令替换为上一步中显示的确切路径。 最后运行'npx create-react-app '

这将取代你的旧文件“create-react-app”,该文件导致了用npx下载的新文件的问题。

快乐的编码…

其他回答

这份工作是给我的:

让我们用下面的命令全局卸载create-react-app:

npm uninstall -g create-react-app

之后在你的项目目录:

npm install create-react-app@latest

最后:

npx create-react-app my-app

对于typescript:

npx create-react-app my-app --template typescript

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

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

But

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

把以上的答案加起来:

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

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

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

请试试这个:

NPX create-react-app project-name——template all