How to export a chart (Highcharts) with offline-exporting to pdf using amd modules? Require the jsPDF module throws "sometime" a requirejs mismatched error or messed up the callback references of other requires.
Question Highcharts Forum: https://www.highcharts.com/forum/viewtopic.php?f=9&t=41929&sid=5178a78a6547d8fb14769a85392b276c
var chart;
require(['highcharts', 'highcharts/modules/exporting', 'highcharts/modules/offline-exporting', 'jsPDF', 'svg2pdf'], function(Highcharts, a, b, jsPDF, svg2pdf) {
window.jsPDF = jsPDF.default;
window.svg2pdf = svg2pdf;
chart = Highcharts.chart('container', {
exporting: {
libURL: 'https://code.highcharts.com/7.1.1/lib'
},
series: [{
data: [3, 4, 5, 3, 2]
}]
});
});
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.15/require.js"></script>
<script>
require.config({
packages: [{
name: 'highcharts',
main: 'highcharts',
location: 'https://code.highcharts.com/7.1.1'
}],
paths: {
'jsPDF': 'https://code.highcharts.com/7.1.1/lib/jspdf',
'svg2pdf': 'https://code.highcharts.com/7.1.1/lib/svg2pdf'
}
});
</script>
</head>
<body>
<div id="container"></div>
</body>
</html>
JsFiddle: https://jsfiddle.net/zbc149wh/2/
Thank you
The issue comes from jsPDF: https://github.com/yWorks/jsPDF
I set a name to all define statements, so there is no more anonymous module definitions. Now it is working.
Example line 3
Before:
typeof define === 'function' && define.amd ? define(['exports'], factory) :
After:
typeof define === 'function' && define.amd ? define('jsPDF', ['exports'], factory) :