Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

depends on 'highcharts'. CommonJS or AMD dependencies can cause optimization bailouts #223

Closed
umamaheshbhamidipati opened this issue Aug 29, 2020 · 6 comments

Comments

@umamaheshbhamidipati
Copy link

depends on 'highcharts'. CommonJS or AMD dependencies can cause optimization bailouts getting this is in angular 10

@mateuszkornecki
Copy link
Contributor

Since Angular 10 the Angular CLI outputs warnings if it detects that your browser application depends on CommonJS modules. We are currently in the middle of migration to the ES-modules, but for now, the only thing that could be done is disabling these warnings. To make it work you can add the CommonJS module name to allowedCommonJsDependencies option in the build options located in the angular.json file.

Official guide of configuring the commonJS dependencies:
https://angular.io/guide/build#configuring-commonjs-dependencies

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

@umamaheshbhamidipati
Copy link
Author

added brother... Thank you for responding...

@shanilkv
Copy link

Since Angular 10 the Angular CLI outputs warnings if it detects that your browser application depends on CommonJS modules. We are currently in the middle of migration to the ES-modules, but for now, the only thing that could be done is disabling these warnings. To make it work you can add the CommonJS module name to allowedCommonJsDependencies option in the build options located in the angular.json file.

Official guide of configuring the commonJS dependencies: https://angular.io/guide/build#configuring-commonjs-dependencies

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

Thank you So Much.!!! It's works

@johancollazosdeveloper
Copy link

Since Angular 10 the Angular CLI outputs warnings if it detects that your browser application depends on CommonJS modules. We are currently in the middle of migration to the ES-modules, but for now, the only thing that could be done is disabling these warnings. To make it work you can add the CommonJS module name to allowedCommonJsDependencies option in the build options located in the angular.json file.

Official guide of configuring the commonJS dependencies: https://angular.io/guide/build#configuring-commonjs-dependencies

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

But this option does not solve the problem, it only removes the warning at the time of compilation or execution of the application.

@ddragula
Copy link
Member

ddragula commented Sep 5, 2024

Hello @johancollazosdeveloper,

You can import Highcharts using ESModules, see: https://www.highcharts.com/docs/getting-started/installation-with-esm

tl;dr:

instead of importing Highcharts & modules this way:

import Highcharts from 'highcharts';
import A11yModule from 'highcharts/modules/accessibility';

A11yModule(Highcharts);

you can import them using es-modules/masters:

import Highcharts from 'highcharts/es-modules/masters/highcharts.src';
import 'highcharts/es-modules/masters/modules/accessibility.src';

or import only the classes you need, e.g.:

import Chart from 'highcharts/es-modules/Core/Chart/Chart.js';
import LineSeries from 'highcharts/es-modules/Series/Line/LineSeries.js';

@PowerKiKi
Copy link

@johancollazosdeveloper, a proper and complete solution is documented on #163 (comment)

(ddragula's suggestion will not lazy-load Highcharts, so your app Initial Total size will be much bigger than it needs to be, leading to poor LCP, possibly leading to poorer Google ranking)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants