doc: recommend node/default conditions for dual packages#62622
Open
akashguptasky wants to merge 2 commits intonodejs:mainfrom
Open
doc: recommend node/default conditions for dual packages#62622akashguptasky wants to merge 2 commits intonodejs:mainfrom
akashguptasky wants to merge 2 commits intonodejs:mainfrom
Conversation
Expand the Dual CommonJS/ES module packages section to explain the dual package hazard and recommend using the "node" and "default" export conditions as the primary approach to avoid it. Fixes: nodejs#52174
Collaborator
|
Review requested:
|
jsumners-nr
approved these changes
Apr 7, 2026
ljharb
reviewed
Apr 8, 2026
doc/api/packages.md
Outdated
| separate copies of the package are loaded. Any state or objects exported by the | ||
| package will not be shared between the two copies. | ||
|
|
||
| ### Approach 1: Use `node` and `default` conditions |
Member
There was a problem hiding this comment.
i'd say approach 0 should be "just use default" - if you use CJS, non-node environments have to bundle. If you use ESM, then CJS consumers can only use it in a node version with require(ESM) support (ESM consumers can always use it, ofc).
Address review feedback by adding Approach 1 that recommends using just the "default" condition with a single format as the simplest solution to the dual package hazard.
Author
|
@ljharb Thank you for the feedback! I've added Approach 1 that recommends using just the |
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.
Expand the "Dual CommonJS/ES module packages" section to explain the dual
package hazard and recommend using the
"node"and"default"exportconditions as the primary approach to avoid it, while keeping the existing
stateful wrapper approach as a secondary option.
Fixes: #52174