【问题标题】:Ionic 5 Angular 11 Cordova build prod - random runtime errors: said method is not a functionIonic 5 Angular 11 Cordova build prod - 随机运行时错误:所述方法不是函数
【发布时间】:2021-07-31 00:43:26
【问题描述】:

我最近从 Ionic 4 Angular 8 升级到 Ionic 5 Angular 11。在浏览器 (ionic build --prod) 和 Android 调试版本 (ionic cordova build android) 中一切正常。当我为 Android 生产模式 (ionic cordova build android --prod) 构建时,我遇到了随机运行时错误,例如:

this.service.method is not a function

e.service.method is not a function

这些错误不会导致崩溃,之后应用程序运行良好,但某些功能已损坏。这只发生在组件和页面中调用的一些服务和方法,我找不到任何模式。可能是什么原因?

将添加更多细节,但目前不知道从哪里开始。

【问题讨论】:

    标签: angular ionic-framework


    【解决方案1】:

    我找到了解决方案,但仍然发布,因为我认为这是构建过程中的一个主要问题,如果您不小心,因为它可以在没有任何明确警告的情况下在随机位置静默破坏您的项目.

    在构建过程中,我收到了一些我(显然)忽略的警告,例如:

    Warning: <path>/app-components-generic.module.ts depends on 'angular2-chartjs'. CommonJS or AMD dependencies can cause optimization bailouts.
    For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
    

    这些“优化救助”实际上似乎破坏了优化和非优化模块之间的引用,这显然会搞砸并导致应用程序在随机位置中断。这实际上是我最好的猜测,因为官方 Angular 文档没有提供这样的警告。

    这是我修复它的方法:

    "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
         ...
         "allowedCommonJsDependencies": [
           "angular2-chartjs",
            ...
         ]
         ...
    

    参考资料:

    【讨论】:

      猜你喜欢
      • 2021-01-13
      • 1970-01-01
      • 1970-01-01
      • 2019-10-05
      • 1970-01-01
      • 2019-04-19
      • 2023-03-31
      • 2019-07-18
      • 1970-01-01
      相关资源
      最近更新 更多