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

知道这是怎么回事吗?


当前回答

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

其他回答

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

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

But

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

如果你之前已经通过npm install -g create-react-app全局安装了create-react-app,我们建议你使用npm uninstall -g create-react-app卸载这个包,以确保npx总是使用最新的版本。

Docs

使用以下命令中的任意一个:

create-react-app my-app NPM init react-app my-app Yarn创建my-app

如果NPM uninstall -g create-react-app上面说的不起作用。 输入create-react-app来知道它被安装在哪里。我的安装在/usr/bin文件夹中。然后执行sudo rm -rf /usr/bin/create-react-app。(感谢下面@v42的评论)

首先卸载create-react-app

npm uninstall -g create-react-app

然后运行yarn create react-app my-app或npx create-react-app my-app

然后运行yarn create react-app my-app或NPX create-react-app my-app可能仍然会给出错误,

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

这可能是因为现金的原因。所以下一组

npm cache clean --force 

然后运行

npm cache verify

现在一切都清楚了。现在运行

Yarn create react-app my-app或NPX create-react-app my-app

现在你会得到你想要的!

第一次全局卸载create-react-app:

npm uninstall -g create-react-app

然后在你的项目目录中:

npm install create-react-app@latest

最后:

npx create-react-app my-app

出现此问题是因为不再支持create-react-app的全局安装。为了解决这个问题,你应该从你的系统中卸载并完全删除create-react-app,所以分别运行这些命令:

npm uninstall -g create-react-app

or

yarn global remove create-react-app

然后用这个命令检查create-react-app是否存在

which create-react-app

如果它返回任何正确的路径,比如

/c/Users/Dell/AppData/Local/Yarn/bin/create-react-app

然后执行该命令全局删除create-react-app

rm -rf /c/Users/Dell/AppData/Local/Yarn/bin/create-react-app

现在你可以用下面的命令创建一个新的react应用程序:

npx create-react-app my-app
npm init react-app my-app
yarn create react-app my-app