【问题标题】:Firebase CommonJS or AMD dependencies can cause optimization bailoutsFirebase CommonJS 或 AMD 依赖项可能导致优化救助
【发布时间】:2020-07-06 08:25:39
【问题描述】:

Angular 10 更新后,我收到了有关 Firebase 和 CommonJS 或 AMD 依赖项的警告!

WARNING in /Users/knewtone/yet/projects/WorkSpace/customers/smart-newtech-dashboard/src/app/app.component.ts depends on 'firebase'. CommonJS or AMD dependencies can cause optimization bailouts. For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

WARNING in /Users/knewtone/yet/projects/WorkSpace/customers/smart-newtech-dashboard/src/app/app.module.ts depends on '@angular/common/locales/fr'. When using the 'localize' option this import is not needed. Did you mean to import '@angular/common/locales/global/fr'? For more info see: https://angular.io/guide/i18n#import-global-variants-of-the-locale-data

WARNING in /Users/knewtone/yet/projects/WorkSpace/customers/smart-newtech-dashboard/src/app/services/crud/crud.service.ts depends on 'lodash/dropRight'. CommonJS or AMD dependencies can cause optimization bailouts. For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

WARNING in /Users/knewtone/yet/projects/WorkSpace/customers/smart-newtech-dashboard/node_modules/@angular/fire/__ivy_ngcc__/fesm2015/angular-fire.js depends on 'firebase/app'. CommonJS or AMD dependencies can cause optimization bailouts. For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

WARNING in /Users/knewtone/yet/projects/WorkSpace/customers/smart-newtech-dashboard/node_modules/firebase/dist/index.cjs.js depends on '@firebase/app'. CommonJS or AMD dependencies can cause optimization bailouts. For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

WARNING in /Users/knewtone/yet/projects/WorkSpace/customers/smart-newtech-dashboard/node_modules/firebase/dist/index.cjs.js depends on '@firebase/database'. CommonJS or AMD dependencies can cause optimization bailouts. For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

WARNING in /Users/knewtone/yet/projects/WorkSpace/customers/smart-newtech-dashboard/node_modules/firebase/dist/index.cjs.js depends on '@firebase/firestore'. CommonJS or AMD dependencies can cause optimization bailouts. For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

WARNING in /Users/knewtone/yet/projects/WorkSpace/customers/smart-newtech-dashboard/node_modules/firebase/dist/index.cjs.js depends on '@firebase/functions'. CommonJS or AMD dependencies can cause optimization bailouts. For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

WARNING in /Users/knewtone/yet/projects/WorkSpace/customers/smart-newtech-dashboard/node_modules/firebase/dist/index.cjs.js depends on '@firebase/performance'. CommonJS or AMD dependencies can cause optimization bailouts. For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

WARNING in /Users/knewtone/yet/projects/WorkSpace/customers/smart-newtech-dashboard/node_modules/firebase/dist/index.cjs.js depends on '@firebase/remote-config'. CommonJS or AMD dependencies can cause optimization bailouts. For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

【问题讨论】:

  • keep track of this。您现在可能需要在angular.json 文件中使用allowedCommonJsDependencies

标签: angular firebase angularfire


【解决方案1】:

要消除这些警告,您可以在 angular.json 中指定以下选项:

"architect": {
        "build": {
                    "builder": "@angular-devkit/build-angular:browser",
                    "options": {
                        "allowedCommonJsDependencies": [
                            "lodash",
                            "firebase",
                            "@angular/common/locales/fr",
                            "lodash/dropRight",
                            "@firebase/app",
                            "firebase/app",
                            "@firebase/database",
                            "@firebase/firestore",
                            "@firebase/functions",
                            "@firebase/performance",
                            "@firebase/remote-config"
                        ],

希望对你有所帮助。

【讨论】:

  • 感谢这让我的警告错误消失了。 "allowedCommonJsDependencies": [ "@firebase/app", "firebase/app", "@firebase/database", "@firebase/util", "@firebase/component", "@firebase/auth"] 。这只是隐藏警告的补丁吗?你认为有更好的方法来实现更好的构建优化吗?
  • 不,这正是官方文档所建议的,更多详细信息请参见下面的 URL angular.io/guide/build#configuring-commonjs-dependencies
  • @IanPostonFramer 是的,这是一种抑制警告的解决方法。您可以在此处找到在 Angular 10 升级后开始发生这种情况的真正原因 - stackoverflow.com/a/62604034/6097025。要修复此捆绑包警告,您需要为其找到正确的 ES6 兼容捆绑包。
  • 官方文档建议仅禁止显示警告,但仍应主要由 firebase 团队修复。
  • @Jonathan github.com/angular/angularfire/issues/2478;我们需要耐心
【解决方案2】:

当你使用一个用 CommonJS 打包的依赖时,可能会导致larger slower applications

从版本 10 开始,Angular 现在会在您的构建拉入其中一个捆绑包时向您发出警告。如果您开始看到有关您的依赖项的这些警告,请让您的依赖项知道您更喜欢 ECMAScript 模块 (ESM) 包。

这是官方文档 - Configuring CommonJS dependencies

您需要像这样更新 angular.json:

    "build": {
    "builder": "@angular-devkit/build-angular:browser",
    "options": {
      "allowedCommonJsDependencies": [
        "firebase",
        "@firebase/app",
        "@firebase/database",
        "@firebase/firestore",
        "@firebase/functions",
        "@firebase/performance",
        "@firebase/remote-config",
        "@firebase/component",
        .... etc ...
     ]
     ...
    }
   ...
},

您可以在我之前的帖子中找到相同的答案 - https://stackoverflow.com/a/62604034/6097025

【讨论】:

  • 虽然这行得通,但我们不应该这样做。尤其是考虑到 Angular 团队应该与 Firebase 团队进行沟通。
猜你喜欢
  • 1970-01-01
  • 2021-03-05
  • 2020-11-30
  • 1970-01-01
  • 2020-10-16
  • 2020-10-16
  • 1970-01-01
  • 2020-11-07
  • 1970-01-01
相关资源
最近更新 更多