export-csv
export-csv copied to clipboard
Possible bug?
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.
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?
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...
But the relevant methods don't show up in Highcharts.Chart.prototype...
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 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);