Ionic start(4.x版本)发生bad status code 400错误以及离线建立新项目的解决方法

使用ionic start建立新项目,出现错误:node

Error: Encountered bad status code (400) for
https://d2ql0qc7j8u4b2.cloudfront.net/angular-official-tabs.tar.gz

This could mean the server is experiencing difficulties right now--please try
again later.
    at Request.req.on.res
(C:\Users\xxx\AppData\Roaming\npm\node_modules\ionic\lib\utils\http.js:68:28)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at Request._emitResponse
(C:\Users\xxx\AppData\Roaming\npm\node_modules\ionic\node_modules\superagent\lib
\node\index.js:862:8)
    at ClientRequest.req.once.res
(C:\Users\xxx\AppData\Roaming\npm\node_modules\ionic\node_modules\superagent\lib
\node\index.js:412:10)
    at Object.onceWrapper (events.js:315:30)
    at emitOne (events.js:121:20)
    at ClientRequest.emit (events.js:211:7)
    at HTTPParser.parserOnIncomingClient (_http_client.js:543:21)
| Downloading and extracting tabs starter (100.00%)

而后就一直卡在Downloading and extracting tabs starter不动。直接缘由是ionic cli没法下载ionic的template文件angular-official-tabs.tar.gz,从url看这个文件没有放在npm库中,因此使用淘宝npm镜像不能解决这个问题。在网上搜了不少文章都没法解决这个问题。git

后来在Ionic官网上看到,Ionic新项目模板(starter)做为一个开源项目托管在github上,因而尝试去找到starter template的源码,而后直接从starter template手工建立新项目。github

在github上搜索ionic-team,发现ionic-team/starters项目,这就是要找的模板源码项目。地址是:npm

https://github.com/ionic-team/starters

而后打包下载这个项目的全部源码。根目录下,有三个文件夹angular、ionic-angular和ionic1三个文件夹,显然分别对应三种ionic4项目的starter模板。angular是ionic4.x的angular项目;ionic-angular是ionic2.x/3.x的项目;ionic1是ionic1.x项目。json

我须要建立的是ionic4.x的项目,因此进入angular文件夹,里面有base和official两个文件夹,从前面错误信息看到下载文件名为angular-official-tabs.tar.gz,因此显然这个模板应该放在official文件夹中。打开official文件夹,里面果真有一个tabs的文件夹,里面有src和e2e两个文件夹,应该就是模板的源文件。可是angular/official/tabs文件夹下没有包含完整的ionic/angular的项目文件,显然,angular.json、package.json文件都没有。而后查找其余文件夹,发现angular/base文件夹下,有这些缺失的文件。因而作如下尝试:浏览器

a.新建一个文件夹做为咱们本身的项目文件夹,假设是testv4。app

b.把angular/base下的全部文件复制到testv4中。ionic

c.把angular/official/tabs文件夹下全部文件复制到testv4中,提示有同名文件,所有覆盖。url

d.把integrations/cordova文件夹下全部文件复制到testv4中.net

编辑testv4/config.xml文件,修改项目名、做者等信息。

若是不存在testv4/ionic.config.json文件,则新建一个,添加如下内容:
{
    "name": "testv4",
    "integrations": {
        "cordova": {}
    },
    "type": "angular"
}

若是testv4/ionic.config.json文件已经存在,则在integrations中添加"cordova": {}。

e.打开testv4/package.json文件,修改前面几行内容为本身的应用名称等:

"name": "ionic-app-base",
  "version": "0.0.0",
  "author": "Ionic Framework",
  "homepage": "https://ionicframework.com/",

f.在testv4文件夹上执行npm install,中间可能会出现错误,若是出错则删除node_module文件夹而后再次运行npm install,直到成功。

g.执行npm run start,启动浏览器打开localhost:4200,成功。

这个方法也能够实现不联网状态下,离线建立Ionic新项目,固然你能够说离线建立新项目没有意义,由于npm install同样须要联网,但若是可以手工创建node_module文件夹,离线建立ionic项目也是有意义的。

相关文章
相关标签/搜索