Skip to content

docs: recommend node/default conditions to avoid dual package hazard#63582

Open
ShahabAhmed01 wants to merge 1 commit into
nodejs:mainfrom
ShahabAhmed01:main
Open

docs: recommend node/default conditions to avoid dual package hazard#63582
ShahabAhmed01 wants to merge 1 commit into
nodejs:mainfrom
ShahabAhmed01:main

Conversation

@ShahabAhmed01
Copy link
Copy Markdown

Fixes #52174

Problem

The current documentation suggests using require/import conditions for dual CommonJS/ESM packages, which can lead to the dual package hazard where Node.js might load both versions of the package.

Solution

Add documentation recommending node/default conditions instead:

  • node: loads the CJS version in Node.js
  • default: loads the ESM version for other platforms (browsers, bundlers)

This approach avoids the dual package hazard while still providing ESM for browsers.

Changes

  • Added "Dual CommonJS/ES module packages" section with dual package hazard explanation
  • Recommended using node/default conditions with example
  • Referenced @babel/runtime as a real-world example

Testing

Documentation-only change, no code changes required.

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders

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.

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

2 participants