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

其他回答

如果你得到这个错误'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下载的新文件的问题。

快乐的编码…

所有的选项在MacOS上都不适用。以下3个步骤是有效的:

从“/usr/local/bin/”目录下删除节点

then

重新安装节点:https://nodejs.org/en/

then

安装react: npx create-react-app my-app follow: https://create-react-app.dev/

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

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 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

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

npm uninstall -g create-react-app

然后在你的项目目录中:

npm install create-react-app@latest

最后:

npx create-react-app my-app