未使用 create-react-app 提供模板

新手上路,请多包涵

当我在终端中键入 create-react-app my-app 命令时,它似乎可以工作 - 成功下载所有库等。在该过程结束时,我收到一条消息,即 template was not provided

输入

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 的 package.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 会改变。

知道这里发生了什么吗?

原文由 SamYoungNY 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 501
2 个回答

如果您之前已经通过 --- create-react-app 全局安装了 --- npm install -g create-react-app ,我们建议您使用 npm uninstall -g create-react-app 卸载该软件包,以确保 npx 始终使用最新版本。

文档

使用以下任一命令:

  • npx create-react-app my-app
  • npm init react-app my-app
  • yarn create react-app my-app

如果 npm uninstall -g create-react-app 上述不起作用。 键入 which create-react-app 以了解它的安装位置。我的安装在 /usr/bin 文件夹中。然后做 sudo rm -rf /usr/bin/create-react-app 。 (归功于下面的@v42 评论)

原文由 Latha Eshappa 发布,翻译遵循 CC BY-SA 4.0 许可协议

1)

 npm uninstall -g create-react-app

要么

yarn global remove create-react-app

2)

似乎存在一个错误,其中 create-react-app 未正确卸载并使用其中一个新命令导致:

未提供模板。这可能是因为您使用的是过时版本的 create-react-app。

使用 npm uninstall -g create-react-app 卸载后,检查您是否仍然“安装”了它 which create-react-app (Windows: where create-react-app )在你的命令上。如果它返回一些东西(例如 /usr/local/bin/create-react-app ),然后执行 rm -rf /usr/local/bin/create-react-app 手动删除。

3)

然后使用以下方法之一:

 npx create-react-app my-app
npm init react-app my-app
yarn create react-app my-app

原文由 Robin Wieruch 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进