Repository navigation
Conversation
Point import at the ES build and require at a .cjs copy of the minified UMD build, with matching .d.ts/.d.cts types, so Node, Vitest and SSR no longer load the UMD bundle as an ES module. Fixes yWorks#394.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #394.
Since the package became
"type": "module",mainpointed Node, Vitest and SSR resolvers atdist/svg2pdf.umd.min.js, which then ran as an ES module. The UMD wrapper falls through to the browser-global branch and throws, and there's no namedsvg2pdfexport. This PR adds anexportsmap:importresolves todist/svg2pdf.es.min.jswithtypes.d.tsrequireresolves todist/svg2pdf.umd.min.cjs, a new rollup output that is the same minified UMD build with a.cjsextension, withdist/types.d.cts./dist/*and./package.jsonstay importable, so deep imports likesvg2pdf.js/dist/svg2pdf.es.min.jskeep workingmainnow points to the.cjsfile.dist/types.d.ctsis copied fromtypes.d.tsduringnpm run build, so the two can't drift. It's needed because TypeScript treatstypes.d.tsas ESM in a"type": "module"package and rejects it forrequireundermoduleResolution: node16(TS1479). The existing dist files come out byte-identical fromnpm run build, and the new dist files are committed because publishing uses the checked-indist.The browser suite can't cover package resolution, so I tested an
npm packtarball installed into a scratch project with jspdf 4.2.1 on Node 22:import 'svg2pdf.js',import { svg2pdf } from 'svg2pdf.js'andrequire('svg2pdf.js')all load, andjsPDF.API.svgis a function. With 2.9.0 from npm, the first and third throw theTypeErrorand the named import is aSyntaxError.dist/import andsvg2pdf.js/package.jsonstill work.ssrLoadModulethat importsvg2pdf.jswork.tscpasses with.mtsand.ctsconsumers undernode16andnodenext, and withbundler. 2.9.0 failsnode16with TS1479.npm run lint,npm run format:checkandnpm run typecheckpass.npm testgives the same result as on master locally: 92 passed and 12 failed, all in the text and diagram snapshot tests, which the README says can differ because of local text measurement.I used an AI coding assistant to help write this; I reviewed the change and ran the tests.