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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions 20 doc/api/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,26 @@ $ node other.js

## Dual CommonJS/ES module packages

Dual packages provide both CommonJS and ES module entry points. A common
approach is to use the `"require"` and `"import"` conditions in `"exports"`
to serve different files depending on whether the package is loaded through
`require()` or `import`. However, this can still lead to the *dual package
hazard*: different parts of an application may end up evaluating separate
copies of the package, one from each module system.

A more robust pattern is to use the `"node"` and `"default"` conditions
instead:

```json
{
"name": "example",
"exports": {
"node": "./index.cjs",
"default": "./index.mjs"
}
}
```

See [the package examples repository][] for details.

## Node.js `package.json` field definitions
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.