Use package entry points for conditional exports between cjs/esm #1249
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 b
2FF9
e 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.
Description of the change
This PR fixes more issues around
import
andrequire
discrepancies by introducing a modern way to define package entry points, called Conditional Exports which were introduced 6 years ago in Node 12.7.0.Conditional Exports replace the legacy
main
,browser
andmodule
fields providing fine-grained control over what files can be imported from our package and how.This change was prompted by the
universal-node
example which wouldn't be able torequire('rollbar')
without suffixing.default
to it. This is because node looked into ourpackage.json
and resolved to use ourmain
field which points to an es module.8000 Note
Before Conditional Exports, packages had to expose main and rely on hacks like pkg.module (non-standard) for ESM builds. Conditional exports made dual packages clean and official.
See the official Proposal for Bare Module Specifier Resolution in node.js
The introduced changes override
main
,browser
andmodule
fields for all nodes >= 12.7.0, and any node < 12 will fallback to the older fields. I'm keeping everything to maximize compatibility.Important
With this change I can confirm that all examples that integrate rollbar through their
package.json
file are 100% working.Type of change
Related issues