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

Fix ES module imports #541

Merged
merged 5 commits into from Feb 5, 2024
Merged

Fix ES module imports #541

merged 5 commits into from Feb 5, 2024

Conversation

fruchtose-stripe
Copy link
Contributor

@fruchtose-stripe fruchtose-stripe commented Feb 2, 2024

Summary & motivation

This PR addresses #527 using conditional exports.

There are two primary changes:

  1. ES modules are now emitted with the .mjs extension
    1. An exports field controls imports of the package and standardizes on extension-free import paths

Exports

The exports field in package.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. Per endoflife.date, security support for Node v12 ended in April 2022. This means that all active and current versions of Node.js support the exports field as included in this PR.

Testing & documentation

I tested this change on a React app made up of .mjs modules, compiled with create-react-app. (Some minor node_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.

This allows conditional exports to work with ES module imports everywhere, not just for code with a build step.
@fruchtose-stripe 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.
cbala-stripe
cbala-stripe previously approved these changes Feb 2, 2024
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 this pull request may close these issues.

None yet

4 participants