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

Commit 5330930

Browse filesBrowse files
guybedfordMylesBorins
authored andcommitted
doc: refine require/import conditions constraints
Backport-PR-URL: #35757 PR-URL: #35311 Reviewed-By: Jan Krems <jan.krems@gmail.com>
1 parent 5f0b157 commit 5330930
Copy full SHA for 5330930

File tree

Expand file treeCollapse file tree

1 file changed

+9
-6
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-6
lines changed
Open diff view settings
Collapse file

‎doc/api/packages.md‎

Copy file name to clipboardExpand all lines: doc/api/packages.md
+9-6Lines changed: 9 additions & 6 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,15 @@ For example, a package that wants to provide different ES module exports for
364364
Node.js supports the following conditions out of the box:
365365

366366
* `"import"` - matched when the package is loaded via `import` or
367-
`import()`. Can reference either an ES module or CommonJS file, as both
368-
`import` and `import()` can load either ES module or CommonJS sources.
369-
_Always matched when the `"require"` condition is not matched._
370-
* `"require"` - matched when the package is loaded via `require()`.
371-
As `require()` only supports CommonJS, the referenced file must be CommonJS.
372-
_Always matched when the `"import"` condition is not matched._
367+
`import()`, or via any top-level import or resolve operation by the
368+
ECMAScript module loader. Applies regardless of the module format of the
369+
target file. _Always mutually exclusive with `"require"`._
370+
* `"require"` - matched when the package is loaded via `require()`. The
371+
referenced file should be loadable with `require()` although the condition
372+
will be matched regardless of the module format of the target file. Expected
373+
formats include CommonJS, JSON, and native addons but not ES modules as
374+
`require()` doesn't support them. _Always mutually exclusive with
375+
`"import"`._
373376
* `"node"` - matched for any Node.js environment. Can be a CommonJS or ES
374377
module file. _This condition should always come after `"import"` or
375378
`"require"`._

0 commit comments

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