当我在我的终端上输入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。 请注意,不再支持create-react-app的全球安装。”

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

NPM卸载-g create-react-app

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

create-react-app new-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下载的新文件的问题。

快乐的编码…

如果你之前已经通过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 --ignore-existing create-react-app [project name]

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

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

对于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也可以。

这解决了我的问题

步骤:

1.卸载create-react应用程序

npm uninstall -g create-react-app

2.现在就用

npx create-react-app my-app

这将自动为u创建模板。