Local Angular library using Highcharts breaks in production mode

Viewed 238

I wrote an Angular library wrapping Highcharts to fit my needs.

When using it locally in dev mode it runs well, but the optimization of the prod mode seems to break it.

The problem comes from the Highcharts module needed to add some features, for example to add new chart types (ie TreeMap). These modules seems not to be loaded in prod mode, resulting in a Highcharts error (https://www.highcharts.com/errors/17/).

This is my first Angular library so the config must be wrong but I can't find where the problem is.

I pushed a minimal reproduction of the problem in this repo: https://github.com/Korbraan/angular-library-opti-bug

First build the library with ng build charts, then try serving it with ng serve --prod. It breaks, but it works with ng serve.

1 Answers

To resolve this issue you have to move modules initialization inside the constructor:

  constructor() {
    const self = this;

    Treemap(self.Highcharts);
    Heatmap(self.Highcharts);
  }
Related