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

reactjs React.js

LEY西门

2020-03-10

当我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.

在的package.json中my-app

"dependencies": {
  "react": "^16.12.0",
  "react-dom": "^16.12.0",
  "react-scripts": "3.3.0" <-- up-to-date
}

我检查了CRA 更改日志,它看起来像添加了对自定义模板的支持-但是看起来命令create-react-app my-app似乎没有更改。

知道这里发生了什么吗?

第445篇《未使用create-react-app提供模板》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

27个回答
MandyJinJin 2020.03.10

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

朔风 2020.03.10

我遇到了同样的问题,并且在我的计算机上全局安装了“ create-react-app”。有错误:

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

然后,我使用此命令删除了先前的安装。

npm卸载-g create-react-app

然后安装新的react应用。

npx create-react-app新应用

YOC60211911 2020.03.10

对于Windows 10,我必须手动删除yarn缓存中的某些文件夹,我的路径类似于C:\Users\username\AppData\Local\Yarn\Cache\v1,而必须除去的折叠类似于npm-create-react-app-1.0.0-1234567890abcdef

米亚Near 2020.03.10

使用命令npm uninstall -g create-react-app对我不起作用。

但这有效:

yarn global remove create-react-app

接着:

npx create-react-app my-app

Pro梅 2020.03.10

这对我有用1.首先通过以下命令全局卸载create-react-app:

npm uninstall -g create-react-app

如果仍然有以前的安装,请完全删除名为“我的应用”的文件夹。(确保没有程序正在使用该文件夹,包括您的终端或cmd程序)

2.然后在您的项目目录中:

npm install create-react-app@latest

3.最后:

npx create-react-app my-app
伽罗卡卡西 2020.03.10

npm uninstall -g create-react-app 在某些情况下可能是一个答案,但在我的情况下不是。

您应该手动删除位于~/.node/bin/或的create-react-app /usr/bin/(只需输入which create-react-app并从使用的位置将其删除rm -rf),然后直接运行即可npm i -g create-react-app

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

null 2020.03.10

这个问题很奇怪,因为昨天对我有用,今天早晨我遇到了同样的错误。根据发行说明,已在支持模板中添加了新功能,因此命令行中的某些部分似乎已更改(例如,--typescript不赞成使用,而赞成使用--template typescript

通过执行以下操作,我确实设法使其全部正常工作:

  1. 卸载全局create-react-app npm uninstall create-react-app -g
  2. 验证npm缓存npm cache verify
  3. 关闭端子。我使用的是Mac终端,如果使用的是IDE,则可能会关闭然后重新打开。
  4. 重新打开终端,浏览至所需项目,然后使用新的模板命令约定通过npx运行create-react-app。为了使其正常工作,我使用了文档站点中的 TypeScriptmy-app来确保一致性:npx create-react-app my-app --template typescript

如果可行,您将看到多个安装:一个安装用于react-scripts,一个安装用于template。错误消息也将不再出现。

米亚乐 2020.03.10

这项工作适合我:

让我们通过以下命令全局卸载create-react-app:

npm uninstall -g create-react-app

之后,在您的项目目录中:

npm install create-react-app@latest

最后:

npx create-react-app my-app

对于 TypeScript:

npx create-react-app my-app --template typescript
LEYJim 2020.03.10

通过从全局npm lib 卸载Mac上解决了这个问题create-react-app,基本上就是这样说,只要尝试做,您还需要这样做sudo

sudo npm uninstall -g create-react-app

然后只需运行:

npx create-react-app my-app-name

现在应该一切正常,并获得如下所示的文件夹结构:

使用create react应用未提供模板

凯番长蛋蛋 2020.03.10

首先卸载create-react-app

npm uninstall -g create-react-app

然后运行yarn create react-app my-appnpx create-react-app my-app

然后运行,yarn create react-app my-app或者npx create-react-app my-app仍然会给出错误,

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

这可能是由于现金而发生的。所以下一次

npm cache clean --force 

然后跑

npm cache verify

现在一切都清楚了。现在运行

yarn create react-app my-app 要么 npx create-react-app my-app

现在您将得到您所期望的!

GilGreen 2020.03.10

这解决了我的问题

脚步:

1.卸载创建反应的应用程序

npm uninstall -g create-react-app

2.现在就使用

npx create-react-app my-app

这将自动为u创建模板。

古一达蒙 2020.03.10

这对我有用!

1) npm uninstall -g create-react-app

2) npm install -g create-react-app

3) npx create-react-app app_name

如果您以前create-react-app通过进行全局安装npm install -g create-react-app,最好使用进行卸载npm uninstall -g create-react-app

LEY小卤蛋 2020.03.10

不能像这样解决此问题,问题出在节点的不同实例中,请尝试删除全局create-react-app,然后从根用户中删除node_modules和package-lock.json

L西里 2020.03.10

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

TLDR;npx --ignore-existing create-react-app

我在Mac上 Mojave 10.15.2

未在全球范围内安装CRA-在一个/usr/local/lib/node_modules/usr/local/bin两个位置均未找到它

然后我遇到了关于CRA的github问题的评论使用--ignore-existing标志运行命令很有帮助。

凯达蒙 2020.03.10

对于Linux,这对我有用

sudo npm uninstall -g create-react-app
npx create-react-app my-test-app
十三村村蛋蛋 2020.03.10

npx create-react-app@latest your-project-name

在尝试了所有答案后为我工作,希望可以对以后的人有所帮助。

TomGil村村 2020.03.10

首先清除npm缓存,然后按以下方式使用yarn:

  • npm cache clean --force
  • npm cache verify
  • yarn create react-app my-app

我希望这有帮助。

卡卡西Near 2020.03.10

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

这是在https://create-react-app.dev/docs/getting-started/上报告的对我来说,这没有用。我不得不在全球范围内重新安装create-react-app。

我要解决此问题的步骤是:

  1. npm卸载-g create-react-app
  2. npm install -g create-react-app
  3. npx create-react-app我的应用
null 2020.03.10

这两个步骤对我有用

1)使用此命令全局卸载react-app

npm uninstall -g create-react-app

2)使用此命令在项目文件夹中安装react-app

npx create-react-app project-name
番长前端 2020.03.10

这对我有用。

  1. npm uninstall -g create-react-app
  2. npx create-react-app my-app
小卤蛋JinJin 2020.03.10
  1. npm install -g create-react-app 在您的电脑中
  2. 再次创建react项目 npx create-react-app my-app
蛋蛋樱 2020.03.10

我也有同样的问题。当我尝试npm init react-app my-app命令返回相同的消息

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

yarn create react-app my-app 命令工作正常。

村村LEY 2020.03.10

要对以上答案加总:

在的新版本中create-react-app,您可以使用自定义模板创建新的应用。到目前为止,有两个模板可用:

  • cra模板
  • 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

凯神乐 2020.03.10

首先通过以下命令全局卸载create-react-app:

npm uninstall -g create-react-app

然后在您的项目目录中:

npm install create-react-app@latest

最后:

npx create-react-app my-app
Eva斯丁 2020.03.10

虽然已经有很多答案了。当我遇到这种情况时,我想出了3种解决方案,并逐步加以应用。


第一步:从官方手册中,

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

https://create-react-app.dev/docs/getting-started

您可以在下面使用这些命令:

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

第二步(如果第一步不起作用):

有时它可能会保留缓存。然后您可以使用下面给出的这些命令。

  • npm uninstall -g create-react-app
  • npm cache clean --force
  • npm cache verify
  • yarn create react-app my-app

第三步:(如果这2个都不起作用)首先通过卸载npm uninstall -g create-react-app,然后which create-react-app在命令行中通过命令检查是否仍然“安装”了它如果您得到类似(/ usr / local / bin / create-react-app)的信息,请运行此命令rm -rf /usr/local/bin/create-react-app(文件夹可能有所不同)以手动删除。然后再次通过npx / npm / yarn安装它。

注意:我在最后一步取得了成功。

凯斯丁 2020.03.10

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),请执行a 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
古一Green 2020.03.10

如果您以前是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

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android