-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Fix jsPDF + Vite compatibility issue #3851 #3903
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
base: master
Are you sure you want to change the base?
Fix jsPDF + Vite compatibility issue #3851 #3903
Conversation
- Add exports field to package.json for proper ES module resolution - Create comprehensive test project demonstrating Vite compatibility - Update imports to use non-minified ES build for better dependency resolution - Add Vite configuration to handle external dependencies gracefully - Verify both development and production builds work correctly This resolves the 'Pre-transform error: failed to resolve import jspdf' error that occurs when using jsPDF with Vite and other modern bundlers. Fixes parallax#3851
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR.
We should structure the exports a bit different:
- don't export the UMD module
- use the es-version for browser only
- use the minified files
"exports": {
"node": "./dist/jspdf.node.min.js"
"browser": "./dist/jspdf.es.min.js"
"types": "./types/index.d.ts"
}
Ideally, we would have a modules build for node, as well, but we can do that later, too.
Move the vite test app to the examples folder and don't commit the dist files.
- Update exports field to use node/browser format with minified files - Remove UMD module from exports as requested - Move test-vite to examples/vite folder - Remove committed dist files from git - Update package.json path reference in example Changes requested by @HackbrettXXX in PR review
@HackbrettXXX Thanks for the feedback! I've made all the requested changes:
The PR is ready for another review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Looks good. The VITE_COMPATIBILITY_FIX.md file explaining the changes. Is that a new GitHub pattern I'm not aware of or should it be removed?
- Remove VITE_COMPATIBILITY_FIX.md as suggested - Format example files with Prettier to pass lint checks
@HackbrettXXX It's not a standard GitHub pattern - I had created it as documentation to explain the fix, but you're right that it's not necessary. I've removed it now along with fixing the linting issues. The PR should be clean now! |
Fix jsPDF + Vite compatibility issue
π― Fixes Issue
Closes #3851
π Problem
jsPDF was not compatible with Vite due to missing
exports
field in package.json, causing:β Solution
exports
field to package.json for proper ES module resolutionπ§ͺ Testing
/test-vite/
project demonstrating full compatibilityimport { jsPDF } from "jspdf"
works correctlyπ Changes Made
exports
field with proper module resolutionVITE_COMPATIBILITY_FIX.md
with solution detailsπ Key Files
package.json
- Added exports configurationtest-vite/
- Comprehensive test projectVITE_COMPATIBILITY_FIX.md
- Solution documentationπ Impact
This fix enables jsPDF to work seamlessly with:
π Hacktoberfest
This contribution resolves a real compatibility issue and improves developer experience for modern JavaScript tooling.