Skip to content

doc: recommend node/default conditions for dual packages#62622

Open
akashguptasky wants to merge 1 commit intonodejs:mainfrom
akashguptasky:doc/recommend-node-default-conditions
Open

doc: recommend node/default conditions for dual packages#62622
akashguptasky wants to merge 1 commit intonodejs:mainfrom
akashguptasky:doc/recommend-node-default-conditions

Conversation

@akashguptasky
Copy link
Copy Markdown

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, while keeping the existing
stateful wrapper approach as a secondary option.

Fixes: #52174

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
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added the doc Issues and PRs related to the documentations. label Apr 7, 2026
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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Issues and PRs related to the documentations.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recommend node/default conditions instead of require/import as a solution to the dual package hazard

4 participants