当我在我的终端上输入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 clear-npx-cache 然后NPX create-react-app my-app 希望它能解决。

其他回答

如果以上这些对你都不起作用,下面就是我所做的: 在ubuntu(可能还有mac和windows)上搜索node_modules文件夹,手动删除create-react-app模块,更新包。Json和包锁。Json,然后再次运行

npx create-react-app <app-name>

作品!

下面的步骤对我很有效

NPM卸载-g create-react-app npx clear-npx-cache NPM I -g create-react-app create-react-app myapp

把以上的答案加起来:

随着新版本的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

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

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