Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

doc: improve dual package hazard section with node/default pattern#60880

Open
ajeeth-asperand wants to merge 1 commit intonodejs:mainnodejs/node:mainfrom
ajeeth-asperand:docs-dual-package-hazardajeeth-asperand/node:docs-dual-package-hazardCopy head branch name to clipboard
Open

doc: improve dual package hazard section with node/default pattern#60880
ajeeth-asperand wants to merge 1 commit intonodejs:mainnodejs/node:mainfrom
ajeeth-asperand:docs-dual-package-hazardajeeth-asperand/node:docs-dual-package-hazardCopy head branch name to clipboard

Conversation

@ajeeth-asperand
Copy link

Fixes: #52174

What

Expands the "Dual CommonJS/ES module packages" section in doc/api/packages.md
to describe the dual package hazard and recommend using "node" / "default"
conditions for dual packages, with a small package.json example.

Why

The existing section only linked to the package examples repository without
describing the recommended pattern. Using "node" / "default" conditions
helps avoid the dual package hazard in Node.js while still allowing other
environments (such as bundlers) to consume an ES module build.

How

  • Described the dual package hazard in more detail.
  • Documented the "node" / "default" export conditions pattern.
  • Added an example package.json snippet.

Testing

  • python tools/test.py doctool

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added the doc Issues and PRs related to the documentations. label Nov 28, 2025
@tats-u
Copy link

tats-u commented Nov 28, 2025

Where is module-sync?

@JakobJingleheimer
Copy link
Member

Thank you, but we already have that covered; it was formerly in the API docs but was moved to a Learn article: https://nodejs.org/en/learn/modules/publishing-a-package

@tats-u
Copy link

tats-u commented Nov 28, 2025

Also we should note that more and more packages in the wild have become ESM-only recently and all Node versions without support for module-sync (older than 20) are EOL today.

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.