Closed markusv closed 3 years ago
Getting same error in our angular project. when running npm audit fix it pulls version 0.10.0.
getting similar error as well
My webpack bundles the html2pdf.js
file. This file does not seem to contain the jspdf library. I think that is due to the webpack config in use in html2pdf.js. The html2pdf.js bundle created here has jspdf and html2canvas marked as externals here . This means webpack will not include them in the bundle called html2pdf.js
. What is the html2pdf.js
bundle meant for? Using the html2pdf.bundle.js
works.
Okay, so an update. First some info:
v10.0.0
I had to switch bundlers from rollup to Webpack, because jsPDF v2+ isn't compatible with rollupdist
, including:
html2pdf.js
, html2pdf.bundle.js
, and their minified counterparts)import
(dist/include/html2pdf.es.js
)require
(dist/require/html2pdf.cjs.js
)Now I'm seeing two big issues. First is what @markusv points out, which is that Webpack is consuming html2pdf.js
when importing/requiring, which it absolutely shouldn't be - it should be respecting the main
and module
fields of package.json
to tell it which file to consume.
Second is that, independent of that (?), the externals
are not working as intended. In the .es.js
and .cjs.js
versions, dependencies are not bundled directly, but are left as imports/requires. This way consumers of html2pdf have some control over the specific versions of jsPDF
and html2canvas
being used, we don't end up with multiple versions, and things can be more optimally bundled.
Again, all of this was working with rollup in v0.9.3. I'm working on finding out what's going wrong with the Webpack config.
I think I've found a solution. My understanding of how Webpack consumes browser
/main
/module
packages was a bit off, so in many cases it's going to use the browser
file (html2pdf.js
). This was true on v0.9.3
with the rollup packages as well.
With rollup, html2pdf.js
was packaged as UMD, and the externals were done in a way that worked both directly in the browser (expecting globals) and in Node (expecting require
s). I'm able to modify how externals are done in Webpack to match that pattern, which should resolve the issue.
I'll try to do an update this evening.
thanks @eKoopmans for looking into this! looking forward to the fix.
It works fine now. Thanks for the quick fix, @eKoopmans 👍
Hi,
I just updated to jspdf version 0.10.0. Unfortunately it does not work for me. I get this error:
Cannot set property 'getPageSize' of undefined
this is my code:
const input = document.getElementById('root'); html2pdf(input);
I have installed html2pdf.js with npm and use webpack to package my project