当我在我的终端上输入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@latest {project name}

这似乎是可行的方法。

其他回答

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

npm uninstall -g create-react-app

然后在你的项目目录中:

npm install create-react-app@latest

最后:

npx create-react-app my-app

我通过从全局npm lib卸载create-react-app来修复Mac上的这个问题,这基本上就是说的,只是尝试去做,你还需要做sudo:

sudo npm uninstall -g create-react-app

然后简单地运行:

npx create-react-app my-app-name

现在应该都好了,并获得如下所示的文件夹结构:

这是一个奇怪的问题,因为这个昨天为我工作,今天早上我遇到了同样的错误。根据发布说明,添加了一个新特性来支持模板,因此看起来命令行中的一些部分已经发生了变化(例如,——typescript被弃用而使用——template typescript)

我做到了以下几点:

卸载全局create-react-app npm npm cache校验。 关闭终端。我使用mac终端,如果使用IDE可能关闭并重新打开。 重新打开终端,浏览到你想要的项目,并通过npx使用新的模板命令约定运行create-react-app。为了让它工作,我使用了文档站点的typescript my-app来确保一致性:npx create-react-app my-app——template typescript

如果运行正常,您应该看到多个安装:一个用于react-scripts,一个用于模板。错误消息也应该不再出现。

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

这似乎是可行的方法。

尝试以管理员身份运行您的终端。我也有同样的问题,除了以管理员身份打开终端,然后执行npx create-react-app yourAppName之外,没有任何帮助