0
votes

While build Angular application getting warning message like as below:

WARNING in /Users/deb/Documents/ProjectName/src/app/services/filename.service.ts depends on 'rxjs/observable/dom/WebSocketSubject'. CommonJS or AMD dependencies can cause optimization bailouts. For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

"allowedCommonJsDependencies": [
            "lodash"
          ],

Even we follow angular guide line its still giving same warning message.

Angular version : 10.x

So how to fix it.

2
the dependency you would need to allow seems to be coming from rxjs and not lodash, so shouldn't you add rxjs or some subset of it to your allowedCommonJsDependencies? - tommueller

2 Answers

0
votes

In the angular doc https://angular.io/guide/build#configuring-commonjs-dependencies

they have just shown to add your dependencies in allowedCommonJsDependencies[] in the options object of angular.json file

please see how i have added my dependencies "allowedCommonJsDependencies": [ "url-join", "lodash", "rxjs/add/observable/forkJoin", "date-fns", "@firebase/component", "@firebase/util", ],

my angular.json file

  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "bcc-ui": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "allowedCommonJsDependencies": [
              "url-join",
              "lodash",
              "rxjs/add/observable/forkJoin",
              "date-fns",
              "@firebase/component",
              "@firebase/util",
              "rxjs/Observable",
              "rxjs/add/operator/map",
              "xlsx",
              "@firebase/auth",
              "rxjs/Rx",
              "jsonschema",
              "fullcalendar",
              "papaparse",
              "handsontable",
              "ajv"
            ],
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "polyfills": "src/polyfills.ts",
            "assets": [
              "src/assets",
              "src/favicon.ico"
            ],
            "styles": [
              "src/styles.less",
              "src/assets/colors.less",
              "src/assets/typography.less",
              "node_modules/aos/dist/aos.css",
              "node_modules/ngx-toastr/toastr.css",
              "node_modules/dropify/dist/css/dropify.css",
              "node_modules/fullcalendar/dist/fullcalendar.min.css",
              "node_modules/nitrozen/_theming.scss",
              "node_modules/fullcalendar-scheduler/dist/scheduler.min.css",
              "node_modules/@swimlane/ngx-datatable/index.css",
              "node_modules/@swimlane/ngx-datatable/assets/icons.css"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.min.js",
              "node_modules/aos/dist/aos.js",
              "node_modules/dropify/dist/js/dropify.min.js"
            ],
            "webWorkerTsConfig": "tsconfig.worker.json"
          },
          "configurations": {
            "production": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            },
            "preProd": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.preprod.ts"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "bcc-ui:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "bcc-ui:build:production"
            },
            "preProd": {
              "browserTarget": "bcc-ui:build:preProd"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "bcc-ui:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "karmaConfig": "./karma.conf.js",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "scripts": [
              "node_modules/dropify/dist/js/dropify.min.js"
            ],
            "styles": [
              "src/styles.less",
              "node_modules/ngx-toastr/toastr.css",
              "node_modules/dropify/dist/css/dropify.css",
              "node_modules/fullcalendar/dist/fullcalendar.min.css",
              "node_modules/fullcalendar-scheduler/dist/scheduler.min.css"
            ],
            "assets": [
              "src/assets",
              "src/favicon.ico"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json",
              "tsconfig.worker.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "bcc-ui-e2e": {
      "root": "e2e",
      "sourceRoot": "e2e",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "./protractor.conf.js",
            "devServerTarget": "bcc-ui:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "e2e/tsconfig.e2e.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "bcc-ui",
  "schematics": {
    "@schematics/angular:component": {
      "prefix": "app",
      "style": "less"
    },
    "@schematics/angular:directive": {
      "prefix": "app"
    }
  },
  "cli": {
    "analytics": "cdf1c241-3c46-42bc-bc3d-b57fb722aef5"
  }
}```
0
votes

my suggest edit your code

"allowedCommonJsDependencies": [
   "rxjs/observable/dom/WebSocketSubject"
],