svg2pdf.js: PDF export does not work when using ES6 modules import
Importing jspdf-yworks and svg2pdf.js as ES6 modules does not work. The jsPDF instance is missing functionality and calling svg2pdf on it will result in an excpetion:
TypeError: o.advancedAPI is not a function
However, when loading the very same svg2pdf and jspdf files via script-tags (directly from /node_modules/), the export works as expected. Thus I assume there is something broken with the ES6 import.
I’ve attached a sample project with webpack and ES6 modules import. To reproduce run
npm install
npm run build
and open /dist/index.html. Then check the DevTools for the exception: es6-modules-test.zip
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 21 (19 by maintainers)
Commits related to this issue
- fix s6 imports (see svg2pdf issue https://github.com/yWorks/svg2pdf.js/issues/59) — committed to yWorks/jsPDF by HackbrettXXX 6 years ago
The fix for es6 imports will come with 2.0.1
You installed the wrong jsPDF:
Please support ES6 modules import, thx.
On their side: https://github.com/MrRio/jsPDF/commit/b6b175a1a4c116a62972099eb00c05914e1a2b82 https://github.com/MrRio/jsPDF/commit/48ca33c6b04094f355ec3a4c2185727ccad3e683 https://github.com/MrRio/jsPDF/commit/ebe19ad52bca0826c1f8aadbf6de24e196d1e7ec
For the es6 imports I use Webpack like with @fskpf’s sample project. This works now when getting rid of
However, with the new build script from MrRio, the AMD require doesn’t work properly anymore:
I suppose the reason is the generated UMD header, that uses the AMD -> CommonJS wrapper: