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

Save error: writeFileSync is not a function #2879

Closed
gerbenmeyer opened this issue Aug 27, 2020 · 7 comments · Fixed by #2881
Closed

Save error: writeFileSync is not a function #2879

gerbenmeyer opened this issue Aug 27, 2020 · 7 comments · Fixed by #2881

Comments

@gerbenmeyer
Copy link

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?

@HackbrettXXX
Copy link
Collaborator

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.

@gerbenmeyer
Copy link
Author

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

@HackbrettXXX
Copy link
Collaborator

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.

@HackbrettXXX
Copy link
Collaborator

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

@gerbenmeyer
Copy link
Author

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

@HackbrettXXX
Copy link
Collaborator

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

@gerbenmeyer
Copy link
Author

Awesome, thanks a lot!

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.

2 participants