-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add conditional exports to package.json #815
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
Conversation
package.json
Outdated
"exports": { | ||
"import": "./dist/signature_pad.js", | ||
"require": "./dist/signature_pad.umd.js", | ||
"default": "./dist/signature_pad.umd.js", |
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.
Looks like it has a problem with the trailing comma in this line
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.
Fixed
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! 💯
## [5.0.5](v5.0.4...v5.0.5) (2025-03-14) ### Bug Fixes * Add conditional exports to package.json ([#815](#815)) ([005a090](005a090))
🎉 This PR is included in version 5.0.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
For posterity, this could be considered a breaking change, see https://nodejs.org/docs/latest-v22.x/api/packages.html#package-entry-points:
Our builds started failing and it took me a bit to figure out what's going on. In parts of our codebase we depended on require('signature_pad/dist/signature_pad.umd') or import SignaturePad from 'signature_pad/dist/signature_pad.umd' which threw errors such as
This can be fixed by changing the above to require('signature_pad') and import SignaturePad from 'signature_pad' respectively. |
I think @niklaas' point is not the fact that we should not have added this, but that the semver was not respected. v5 should have the old paths listed undert he "exports": {
"import": "./dist/signature_pad.js",
"require": "./dist/signature_pad.umd.js",
"default": "./dist/signature_pad.umd.js",
"./dist/signature_pad.js": "./dist/signature_pad.js",
"./dist/signature_pad.min.js": "./dist/signature_pad.min.js",
"./dist/signature_pad.umd.js": "./dist/signature_pad.umd.js",
"./dist/signature_pad.umd.min.js": "./dist/signature_pad.umd.min.js",
}, And then in 6.0.0 remove it |
Yes and my point is that if we need to change the major version every time it could break someone using it the way it wasn't intended to be used we would only ever release major versions. |
I wrote this hoping to help someone else if they come across the same issue in the future. |
The intention was to preserve backwards compatibility, and not knowing that import/require/defaults covered more than what "main" and (non-standard) "module" covered. If adding |
I'm in the process of updating to Node 22 and I ran into an issue with the default export not working:
This PR fixes compatibility with TypeScript's
"nodenext"
module resolution. The"module"
property is non-standard and not supported by node. The official way is "Conditional Exports":https://nodejs.org/docs/latest-v22.x/api/packages.html#conditional-exports
This is needed for packages that support CommonJS and ESM where the
"type"
is omitted or set to"commonjs"
.(Note: "require" could be omitted, but I was more explicit including both "require" and "default")