当我在我的终端上输入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 create-react-app project-name——template all

其他回答

如果你之前已经通过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

没有人提到最基本的问题, Windows用户。 确保您更新了节点版本。 这些答案都不适合我,直到我更新了我的node.js

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

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

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

这对我很有效 1.第一次全局卸载create-react-app:

npm uninstall -g create-react-app

如果你还有以前的安装,请删除文件夹叫我的应用程序完全。(确保没有程序正在使用该文件夹,包括您的终端或cmd提示符)

2.然后在你的项目目录中:

npm install create-react-app@latest

3.最终:

npx create-react-app my-app