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
Fix ES module imports #541
Merged
Merged
Conversation
This file contains 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
This allows conditional exports to work with ES module imports everywhere, not just for code with a build step.
fruchtose-stripe
force-pushed
the
fruchtose/exports
branch
from
February 2, 2024 23:18
a230207
to
b0df80b
Compare
fruchtose-stripe
changed the title
Add exports field to package.json
Fix ES module imports
Feb 2, 2024
This change removes the old pure.js shim from the top-level directory and fixes types for the now-extension-free pure module.
fruchtose-stripe
force-pushed
the
fruchtose/exports
branch
from
February 2, 2024 23:26
e2852b7
to
37541fc
Compare
fruchtose-stripe
force-pushed
the
fruchtose/exports
branch
from
February 2, 2024 23:27
37541fc
to
c8c6d3e
Compare
cbala-stripe
previously approved these changes
Feb 2, 2024
cbala-stripe
approved these changes
Feb 5, 2024
This was referenced Feb 12, 2024
Open
This was referenced Feb 12, 2024
This was referenced Feb 12, 2024
This was referenced Feb 16, 2024
Closed
Closed
This was referenced Feb 19, 2024
1 task
This was referenced Feb 19, 2024
This was referenced Feb 23, 2024
This was referenced Mar 1, 2024
1 task
This was referenced Apr 13, 2024
1 task
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.
Summary & motivation
This PR addresses #527 using conditional exports.
There are two primary changes:
.mjs
extensionexports
field controls imports of the package and standardizes on extension-free import pathsExports
The
exports
field inpackage.json
standardizes imports on two targets:@stripe/stripe-js
@stripe/stripe-js/pure
Support for the
exports
field was first added to Node v12.7 back in July 2019. Support for conditional exports was added to Node v12.16 in February 2020. Perendoflife.date
, security support for Node v12 ended in April 2022. This means that all active and current versions of Node.js support theexports
field as included in this PR.Testing & documentation
I tested this change on a React app made up of
.mjs
modules, compiled withcreate-react-app
. (Some minornode_modules
editing was required to allow the webpack config in CRA to work with ES modules.)All documentation in
README.md
points to the two module names mentioned above, so documentation changes are not strictly needed.Alternatives considered
Another possible fix would be to rename the output files to use the
.mjs
extension. However, this strategy is less ideal because it would require users to use different imports depending on their package setup.