Jspdf: Save error: writeFileSync is not a function

Created on 27 Aug 2020  路  7Comments  路  Source: MrRio/jsPDF

In the latest version of jsPDF (2.1.0), when trying to save a document, I'm getting the following error:

TypeError: r.writeFileSync is not a function
    at Object.N.save (jspdf.js:5669)

I'm importing jsPDF as import { jsPDF } from 'jspdf';, and am using jspdf client-side. Any idea on how to solve this?

Most helpful comment

Could you test if your app works with the files from the pull request (you need to run npm run build first)?

All 7 comments

In which context do you run the app? Especially which build tools do you use? Seems like the build tool uses the node variant instead of the es modules variant.

We're using parcel v2 for bundling. What other context information would you need?

Could reproduce it.

Seems like parcel 2 behaves differently than parcel 1, rollup and webpack: if the "browser" field in the package.json is not specified, it uses the "main" field. So the order of fields, which parcel 2 uses to resolve a module's entry point, is browser > main > module. In the other bundlers it is browser > module > main. Not sure if this inconsistency with the other bundlers is good from parcel's side, but I think we can fix the issue for jsPDF by providing a "browser" field with the same entry as the "module" field.

I'll quickly prepare a pull request.

Could you test if your app works with the files from the pull request (you need to run npm run build first)?

When installing jspdf directly from your branch, it is indeed working!

Great! I'll merge it and I will probably prepare a bugfix release next week.

Awesome, thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

centurianii picture centurianii  路  4Comments

yankeeBrit picture yankeeBrit  路  3Comments

NoFootDancer picture NoFootDancer  路  3Comments

sayo96 picture sayo96  路  3Comments

andmaltes picture andmaltes  路  4Comments