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

知道这是怎么回事吗?


当前回答

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

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标志运行该命令会有所帮助。

其他回答

这对我很管用!

1) NPM卸载-g create-react-app

2) NPM install -g create-react-app

3) NPX create-react-app app_name

如果你之前通过npm install -g create-react-app全局安装了任何create-react-app,最好使用npm uninstall -g create-react-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 uninstall -g create-react-app在某些情况下可能是一个答案,但在我的情况下不是。

您应该手动删除位于~/的create-react-app。Node /bin/或/usr/bin/(只需输入create-react-app,并使用rm -rf将其从您看到的位置删除),接下来只需运行NPM I -g create-react-app。

之后,create-react-app将正常工作。

npx create-react-app@latest {project name}

这似乎是可行的方法。

我也遇到了同样的问题,我已经在我的机器上全局安装了“创建-反应-应用程序”。 有错误:

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

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

NPM卸载-g create-react-app

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

create-react-app new-app