Skip to content

Commit 5330930

Browse files
guybedfordMylesBorins
authored andcommitted
doc: refine require/import conditions constraints
Backport-PR-URL: #35757 PR-URL: #35311 Reviewed-By: Jan Krems <[email protected]>
1 parent 5f0b157 commit 5330930

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

doc/api/packages.md

+9-6
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)