Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Bedford <guybedford@gmail.com>2020-09-23 06:35:47 +0300
committerMyles Borins <mylesborins@github.com>2020-09-29 18:43:20 +0300
commit5da5d41b1c172fb2c16138f7fb3ced55005273fc (patch)
tree3f137d246b1f533281be858d4d8b636fe2aef7a9 /doc/api/packages.md
parent482ce6ce1d5237117709b5ec0a569ee7b379bd06 (diff)
doc: refine require/import conditions constraints
PR-URL: https://github.com/nodejs/node/pull/35311 Reviewed-By: Jan Krems <jan.krems@gmail.com>
Diffstat (limited to 'doc/api/packages.md')
-rw-r--r--doc/api/packages.md15
1 files changed, 9 insertions, 6 deletions
diff --git a/doc/api/packages.md b/doc/api/packages.md
index 997ffae76a5..737e777550c 100644
--- a/doc/api/packages.md
+++ b/doc/api/packages.md
@@ -364,12 +364,15 @@ For example, a package that wants to provide different ES module exports for
Node.js supports the following conditions out of the box:
* `"import"` - matched when the package is loaded via `import` or
- `import()`. Can reference either an ES module or CommonJS file, as both
- `import` and `import()` can load either ES module or CommonJS sources.
- _Always matched when the `"require"` condition is not matched._
-* `"require"` - matched when the package is loaded via `require()`.
- As `require()` only supports CommonJS, the referenced file must be CommonJS.
- _Always matched when the `"import"` condition is not matched._
+ `import()`, or via any top-level import or resolve operation by the
+ ECMAScript module loader. Applies regardless of the module format of the
+ target file. _Always mutually exclusive with `"require"`._
+* `"require"` - matched when the package is loaded via `require()`. The
+ referenced file should be loadable with `require()` although the condition
+ will be matched regardless of the module format of the target file. Expected
+ formats include CommonJS, JSON, and native addons but not ES modules as
+ `require()` doesn't support them. _Always mutually exclusive with
+ `"import"`._
* `"node"` - matched for any Node.js environment. Can be a CommonJS or ES
module file. _This condition should always come after `"import"` or
`"require"`._