fusioncharts / angular-fusioncharts

Angular Component for FusionCharts JavaScript Charting Library
https://fusioncharts.github.io/angular-fusioncharts/#/ex1
Other
55 stars 37 forks source link

angular-fusioncharts is throwing an error while implementing FusionCharts as ES6 module #72

Closed soumyasankarduttagit closed 4 years ago

soumyasankarduttagit commented 4 years ago

angular-fusioncharts is throwing an error while implementing FusionCharts as ES6 module

Sample replicating the issue https://www.dropbox.com/s/2og83hv947cw6rw/IssueFusionCharts.zip?dl=0 Please check the following error log image

priyanjitdey94 commented 4 years ago

@soumyasdutta When you are implementing FusionCharts as ES modules, you should not import it as follows: import * as FusionCharts from 'fusioncharts/core';

Please change

import * as FusionCharts from "fusioncharts/core";
import * as Column2d from "fusioncharts/viz/column2d";
import * as FusionTheme from "fusioncharts/themes/fusioncharts.theme.fusion";

to

import FusionCharts from "fusioncharts/core";
import Column2d from "fusioncharts/viz/column2d";
import FusionTheme from "fusioncharts/themes/fusioncharts.theme.fusion";

In ES modules, import * returns a module object which contains all the parameters that are exported within that module(both named and default export).

Consider,

const array = [1, 2, 3];

class Random {}

export { array }; // named export
export default Random; // default export

If we import it as *, then we will get an object of roughly the following structure

{
    array: [],
    default: class Random
}

So, a module which is expecting the Random class will receive an object containing a default property set to Random class. Hence, the error.