export-csv icon indicating copy to clipboard operation
export-csv copied to clipboard

Possible bug?

Open unitymarc opened this issue 8 years ago • 3 comments

This commit... https://github.com/highcharts/export-csv/commit/2210b5d7929b825160f289b62650abda53277ed8 ...seems to break export-csv for me. Maybe I'm being an idiot?

    if (typeof module === 'object' && module.exports) {
         module.exports = factory;
    } else {
         factory(Highcharts);
    }

If we fall into the first clause, there's no opportunity for factory() to run. So the methods never get added to Highcharts.Chart.prototype. On the other hand...

    if (typeof module === 'object' && module.exports) {
         module.exports = factory;
    }
    factory(Highcharts);

Works just fine for me. Apologies if I'm being thick.

unitymarc avatar Mar 02 '16 00:03 unitymarc

By assigning the factory to module.exports, this will run in a CommonJS environment. The only case where I can see this failing is if you have defined an object called module, containing a property called exports, and it is not CommonJS.

This patterns is consistent with how it is done for example in jQuery.

@jon-a-nygaard Any comments?

TorsteinHonsi avatar Mar 04 '16 12:03 TorsteinHonsi

Hmmm....well, perhaps there's some other explanation that's eluding me. If I change back to your code, I can see the module.exports in window...

screen shot 2016-03-04 at 1 26 27 pm

But the relevant methods don't show up in Highcharts.Chart.prototype...

screen shot 2016-03-04 at 1 27 17 pm

With my fix, I get it all and my life is good. We're operating within an AngularJS page, if that's helpful or relevant.

unitymarc avatar Mar 04 '16 21:03 unitymarc

@unitymarc I am not sure if you are using Node.js, but if so you will have to execute the Highcharts modules after requiring them. Examples below.

var Highcharts = require('highcharts');
// Require and execute export csv module
require('_path_to_export_csv')(Highcharts);

// Alternative method, store the Exports CSV factory function to execute it on a later stage.
var Highcharts = require('highcharts');
// Require and and store export csv factory function
var ExportCSV = require('_path_to_export_csv');
// Execute the factory function
ExportCSV(Highcharts);

jon-a-nygaard avatar Mar 07 '16 08:03 jon-a-nygaard