在prod模式下执行ionic 2 Android应用程序时出错,无法找到模块ngfactory

时间:2017-03-28 10:59:57

标签: android cordova angular typescript ionic2

使用--prod标志

执行和ionic2 app时出现此错误

enter image description here

在闪屏加载后屏幕变白。

我们发布的命令是:

  

离子运行android --prod

我们正在使用部署设备,Nexus 5x(与模拟器的行为相同)

离子信息:

apache cordova 6.4.0
Ionic Framework Version: 2.1.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.2.0
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 7
Node Version: v6.5.0
Xcode version: Not installed

Cordova插件:

enter image description here

这些是我们对package.json的依赖:

"dependencies": {
"@angular/common": "2.1.1",
"@angular/compiler": "2.1.1",
"@angular/compiler-cli": "2.1.1",
"@angular/core": "2.1.1",
"@angular/forms": "2.1.1",
"@angular/http": "2.1.1",
"@angular/platform-browser": "2.1.1",
"@angular/platform-browser-dynamic": "2.1.1",
"@angular/platform-server": "2.1.1",
"@ionic/storage": "1.1.6",
"angular2-google-maps": "0.16.0",
"ionic-angular": "2.1.0",
"ionic-native": "2.5.1",
"ionicons": "3.0.0",
"localforage": "1.4.3",
"localforage-cordovasqlitedriver": "1.5.0",
"rxjs": "5.0.0-beta.12",
"saml2-js": "1.11.0",
"tslint": "4.0.0",
"zone.js": "0.6.26"
}

我们的devDependencies:

"devDependencies": {
"@ionic/app-scripts": "^1.2.2",
"@types/jasmine": "2.5.38",
"@types/node": "7.0.4",
"angular-cli": "1.0.0-beta.21",
"codelyzer": "2.0.0-beta.1",
"electron": "1.4.12",
"electron-builder": "11.2.3",
"electron-packager": "8.5.0",
"jasmine-core": "2.5.2",
"karma": "1.3.0",
"karma-chrome-launcher": "2.0.0",
"karma-cli": "1.0.1",
"karma-jasmine": "1.0.2",
"karma-mocha-reporter": "2.2.1",
"karma-remap-istanbul": "0.2.1",
"sw-toolbox": "3.5.1",
"typescript": "^2.0.9"
}

tsconfig.json内容:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es6"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,   
    "target": "es5",
    "baseUrl": ".",
    "paths": {
      "@app/*": [ "src/*" ]
    },
    "types": [ "node" ]
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

正如您所看到的,我们已将离子脚本更新为最新版本,只是为了检查问题是否已解决,但没有运气。

使用相同的堆栈和1.2.0版本的@ ionic / app-scripts,似乎生成了ngfactory文件,但是我们还有另一个错误(在运行时):

enter image description here

缩放:

enter image description here

我们在github上看到了一个关于此错误的问题,但修复了错误,建议更新到1.2.1版本,并再次出现错误"找不到模块..ngfactory"

https://forum.ionicframework.com/t/error-after-updating-app-scripts-to-1-2-0/84207

https://github.com/driftyco/ionic-app-scripts/issues/836

知道为什么不在这些版本的捆绑包内生成ngfactory文件?

任何帮助都应该受到赞赏,因为这是在生产中放置一个非常棒且非常完整的应用程序的最新步骤,以减少开始时的加载时间。 提前感谢您的无可比拟的帮助。

此致

2 个答案:

答案 0 :(得分:0)

删除" ^"之前签署" typescript"和" @ionic/app-scripts" package.json中的包。它应该如下所示:

"typescript": "2.0.9",
"@ionic/app-scripts": "1.2.2"

运行npm install然后重试。

答案 1 :(得分:0)

我们发现了这个问题。已经解决了几件事:

1)使用这些依赖项更新package.json:

  "dependencies": {
    "@angular/common": "2.4.8",
    "@angular/compiler": "2.4.8",
    "@angular/compiler-cli": "2.4.8",
    "@angular/core": "2.4.8",
    "@angular/forms": "2.4.8",
    "@angular/http": "2.4.8",
    "@angular/platform-browser": "2.4.8",
    "@angular/platform-browser-dynamic": "2.4.8",
    "@angular/platform-server": "2.4.8",
    "@ionic/storage": "1.1.6",
    "ionic-angular": "2.3.0",
    "ionic-native": "2.5.1",
    "ionicons": "3.0.0",
    "localforage": "1.4.3",
    "localforage-cordovasqlitedriver": "1.5.0",
    "angular2-google-maps": "0.16.0",
    "saml2-js": "1.11.0",
    "rxjs": "5.0.1",
    "sw-toolbox": "3.4.0",
    "zone.js": "0.7.2"
  },
  "devDependencies": {
    "@ionic/app-scripts": "1.2.2",
    "typescript": "2.0.9",
    "tslint": "4.0.0"
  },

2)删除了我们在package.json上的配置:

"config": {
    "ionic_bundler": "webpack",
    "ionic_source_map_type": "#inline-source-map"
  }

默认情况下,离子2使用webpack,因此是多余的。 唯一的问题是删除这一行:

"ionic_source_map_type": "#inline-source-map"

我们无法直接在浏览器上使用typescript进行调试,但我们会根据环境生成不同的配置。

好消息是我们的应用程序仅在3秒而不是12秒内在Android Nexus 5X上运行,javascript包从14Mb减少到2Mb,所以它值得!感谢离子2人为那个很棒的框架和那些很棒的脚本。该应用程序在中型移动设备上表现非常出色,因此对于我们而言,它接近本机,并且仅在3个月内开发用于ios(尚未测试)和android,我们对结果非常满意。 / p>

希望这篇文章能帮助某人

祝你有个美好的一天!