gmazzamuto / ng2-google-charts

Angular Google Charts module
https://www.devrandom.it/software/ng2-google-charts/
MIT License
120 stars 64 forks source link

Breaks universal ssr when module gets loaded #116

Closed bkielczewski closed 4 years ago

bkielczewski commented 4 years ago

In bundles/ng2-google-charts.umd.js you have:

(function webpackUniversalModuleDefinition(root, factory) {
    if(typeof exports === 'object' && typeof module === 'object')
        module.exports = factory(require("@angular/core"));
    else if(typeof define === 'function' && define.amd)
        define(["@angular/core"], factory);
    else if(typeof exports === 'object')
        exports["ng2-google-charts.umd"] = factory(require("@angular/core"));
    else
        root["ng2-google-charts.umd"] = factory(root["@angular/core"]);
})(window, function(__WEBPACK_EXTERNAL_MODULE__0__) {

Obviously resulting in ReferenceError: window is not defined when Ng2GoogleChartsModule is loaded server-side.

bkielczewski commented 4 years ago

I've noticed this comes from ngm-cli you're using for your build. My advice would be to consider switching to Angular CLI library project for your build. The bundles it generates don't have window object passed if it's not used and in general it's a 'more Angular way' of achieving the same without relying on other 3rd party projects.

gmazzamuto commented 4 years ago

I have already switched just after I saw the issue, I'll release a new version soon

bkielczewski commented 4 years ago

Great, thanks!