Upgrading to Angular 10 - Fix CommonJS or AMD dependencies can cause optimization bailouts

前端 未结 5 1598
一向
一向 2020-12-15 02:36

I am trying to upgrade my angular 9 app to angular 10 version, but getting below warning after the upgrade

rxjs\\BehaviorSubject.js depends on rxjs-compat/Beh         


        
相关标签:
5条回答
  • 2020-12-15 02:58
      "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
         "allowedCommonJsDependencies": [
            "lodash"
         ]
         ...
       }
       ...
    },
    

    Its working in my case Angular CLI 10.1.0. Ref: https://angular.io/guide/build#configuring-commonjs-dependencies

    0 讨论(0)
  • 2020-12-15 03:09

    It is recommended that you avoid depending on CommonJS modules in your Angular applications. Depending on CommonJS modules can prevent bundlers and minifiers from optimizing your application, which results in larger bundle sizes. Instead, it is recommended that you use ECMAScript modules in your entire application.Still you don't care about your bundling size,

    To disable these warnings, you can add the CommonJS module name to allowedCommonJsDependencies option in the build options located in angular.json file.

    "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
         "allowedCommonJsDependencies": [
            "rxjs-compat"
         ]
         ...
       }
       ...
    },
    

    Source

    0 讨论(0)
  • 2020-12-15 03:11

    When you use a dependency that is packaged with CommonJS, it can result in larger slower applications

    Starting with version 10, Angular now warns you when your build pulls in one of these bundles. If you’ve started seeing these warnings for your dependencies, let your dependency know that you’d prefer an ECMAScript module (ESM) bundle.

    Here is an official documentation - Configuring CommonJS dependencies

    "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
         "allowedCommonJsDependencies": [
            "rxjs-compat",
             ... 
         ]
         ...
       }
       ...
    },
    
    0 讨论(0)
  • 2020-12-15 03:16

    try replacing the rxjs imports rxjs/internal/operators with rxjs/operators.

    ex:

    import { catchError, retry } from 'rxjs/internal/operators';
    

    with

    import { catchError, retry } from 'rxjs/operators';
    
    0 讨论(0)
  • 2020-12-15 03:16

    For RXJS library you can do following changes.

    For imports such as 'rxjs/internal/<anything>' and 'rxjs/index', replace it with just 'rxjs'.

    For imports such as 'rxjs/internal/operators', replace it with 'rxjs/operators', which is mentioned in @Janardhan Burle's answer.

    0 讨论(0)
提交回复
热议问题