Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set property 'getPageSize' of undefined in version 0.10.0 #464

Closed
markusv opened this issue Aug 31, 2021 · 7 comments · Fixed by #470
Closed

Cannot set property 'getPageSize' of undefined in version 0.10.0 #464

markusv opened this issue Aug 31, 2021 · 7 comments · Fixed by #470

Comments

@markusv
Copy link

markusv commented Aug 31, 2021

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

Skjermbilde 2021-08-31 kl  12 46 28

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

@bhiapp4
Copy link

bhiapp4 commented Aug 31, 2021

Getting same error in our angular project. when running npm audit fix it pulls version 0.10.0.

@ghost
Copy link

ghost commented Sep 1, 2021

getting similar error as well

Screen Shot 2021-08-31 at 9 28 16 PM

new

@markusv
Copy link
Author

markusv commented Sep 1, 2021

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.

@eKoopmans
Copy link
Owner

Okay, so an update. First some info:

  • in v10.0.0 I had to switch bundlers from rollup to Webpack, because jsPDF v2+ isn't compatible with rollup
  • html2pdf produces several assets in dist, including:
    • files specifically intended for the browser (html2pdf.js, html2pdf.bundle.js, and their minified counterparts)
    • a file intended for when html2pdf is imported via ES6 import (dist/include/html2pdf.es.js)
    • a file intended for when html2pdf is required via Node require (dist/require/html2pdf.cjs.js)
  • this pattern was working fine until now (with rollup)

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.

@eKoopmans
Copy link
Owner

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 requires). 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.

@ghost
Copy link

ghost commented Sep 1, 2021

thanks @eKoopmans for looking into this! looking forward to the fix.

@markusv
Copy link
Author

markusv commented Sep 2, 2021

It works fine now. Thanks for the quick fix, @eKoopmans 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants