@@ -446,7 +446,7 @@ For example, a package that wants to provide different ES module exports for
446
446
}
447
447
```
448
448
449
- Node.js supports the following conditions out of the box :
449
+ Node.js implements the following conditions:
450
450
451
451
* ` "import" ` - matches when the package is loaded via ` import ` or
452
452
` import() ` , or via any top-level import or resolve operation by the
@@ -469,11 +469,6 @@ matching, earlier entries have higher priority and take precedence over later
469
469
entries. _ The general rule is that conditions should be from most specific to
470
470
least specific in object order_ .
471
471
472
- Other conditions such as ` "browser" ` , ` "electron" ` , ` "deno" ` , ` "react-native" ` ,
473
- etc., are unknown to Node.js, and thus ignored. Runtimes or tools other than
474
- Node.js can use them at their discretion. Further restrictions, definitions, or
475
- guidance on condition names might occur in the future.
476
-
477
472
Using the ` "import" ` and ` "require" ` conditions can lead to some hazards,
478
473
which are further explained in [ the dual CommonJS/ES module packages section] [ ] .
479
474
@@ -544,6 +539,52 @@ exports, while resolving the existing `"node"`, `"default"`, `"import"`, and
544
539
545
540
Any number of custom conditions can be set with repeat flags.
546
541
542
+ ### Conditions Definitions
543
+
544
+ The ` "import" ` , ` "require" ` , ` "node" ` and ` "default" ` conditions are defined
545
+ and implemented in Node.js core,
546
+ [ as specified above] ( #esm_conditional_exports ) .
547
+
548
+ Other condition strings are unknown to Node.js and thus ignored by default.
549
+ Runtimes or tools other than Node.js can use them at their discretion.
550
+
551
+ These user conditions can be enabled in Node.js via the [ ` --conditions `
552
+ flag] ( #packages_resolving_user_conditions ) .
553
+
554
+ The following condition definitions are currently endorsed by Node.js:
555
+
556
+ * ` "browser" ` - any environment which implements a standard subset of global
557
+ browser APIs available from JavaScript in web browsers, including the DOM
558
+ APIs.
559
+ * ` "development" ` - can be used to define a development-only environment
560
+ entry point. _ Must always be mutually exclusive with ` "production" ` ._
561
+ * ` "production" ` - can be used to define a production environment entry
562
+ point. _ Must always be mutually exclusive with ` "development" ` ._
563
+
564
+ The above user conditions can be enabled in Node.js via the [ ` --conditions `
565
+ flag] ( #packages_resolving_user_conditions ) .
566
+
567
+ Platform specific conditions such as ` "deno" ` , ` "electron" ` , or ` "react-native" `
568
+ may be used, but while there remain no implementation or integration intent
569
+ from these platforms, the above are not explicitly endorsed by Node.js.
570
+
571
+ New conditions definitions may be added to this list by creating a PR to the
572
+ [ Node.js documentation for this section] [ ] . The requirements for listing a
573
+ new condition definition here are that:
574
+
575
+ * The definition should be clear and unambigious for all implementers.
576
+ * The use case for why the condition is needed should be clearly justified.
577
+ * There should exist sufficient existing implementation usage.
578
+ * The condition name should not conflict with another condition definition or
579
+ condition in wide usage.
580
+ * The listing of the condition definition should provide a coordination
581
+ benefit to the ecosystem that wouldn't otherwise be possible. For example,
582
+ this would not necessarily be the case for company-specific or
583
+ application-specific conditions.
584
+
585
+ The above definitions may be moved to a dedicated conditions registry in due
586
+ course.
587
+
547
588
### Self-referencing a package using its name
548
589
549
590
Within a package, the values defined in the package’s
@@ -1053,6 +1094,7 @@ This field defines [subpath imports][] for the current package.
1053
1094
[CommonJS]: modules .md
1054
1095
[ES module ]: esm .md
1055
1096
[ES modules]: esm .md
1097
+ [Node .js documentation for this section]: https: // github.com/nodejs/node/blob/master/doc/api/packages.md#conditions-definitions
1056
1098
[` ERR_PACKAGE_PATH_NOT_EXPORTED` ]: errors .md #errors_err_package_path_not_exported
1057
1099
[` esm` ]: https: // github.com/standard-things/esm#readme
1058
1100
[` "exports"` ]: #packages_exports
0 commit comments