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

知道这是怎么回事吗?


当前回答

在你的电脑上安装-g create-react-app 用NPX Create -react-app my-app再次创建react项目

其他回答

在你的电脑上安装-g create-react-app 用NPX Create -react-app my-app再次创建react项目

这对我很管用!

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卸载它

如果你之前已经通过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,您可以使用自定义模板创建一个新的应用程序。 目前有两个模板可用:

cra-template cra-template-typescript

用法:

npx create-react-app my-app [--template typescript]

更多关于create-react-app的最新变化:

https://github.com/facebook/create-react-app/releases/tag/v3.3.0

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将正常工作。