@@ -537,6 +537,11 @@ Node.js implements the following conditions:
537
537
* ` "node" ` - matches for any Node.js environment. Can be a CommonJS or ES
538
538
module file. _ This condition should always come after ` "import" ` or
539
539
` "require" ` ._
540
+ * ` "node-addons" ` - similar to ` "node" ` and matches for any Node.js environment.
541
+ This condition can be used to provide an entry point which uses native C++
542
+ addons as opposed to an entry point which is more universal and doesn't rely
543
+ on native addons. This condition can be disabled via the
544
+ [ ` --no-addons ` flag] [ ] .
540
545
* ` "default" ` - the generic fallback that always matches. Can be a CommonJS
541
546
or ES module file. _ This condition should always come last._
542
547
@@ -615,16 +620,22 @@ node --conditions=development main.js
615
620
```
616
621
617
622
which would then resolve the ` "development" ` condition in package imports and
618
- exports, while resolving the existing ` "node" ` , ` "default " ` , ` "import " ` , and
619
- ` "require" ` conditions as appropriate.
623
+ exports, while resolving the existing ` "node" ` , ` "node-addons " ` , ` "default " ` ,
624
+ ` "import" ` , and ` " require"` conditions as appropriate.
620
625
621
626
Any number of custom conditions can be set with repeat flags.
622
627
623
628
### Conditions Definitions
624
629
625
- The ` "import" ` , ` "require" ` , ` "node" ` and ` "default" ` conditions are defined
626
- and implemented in Node.js core,
627
- [ as specified above] ( #packages_conditional_exports ) .
630
+ The ` "import" ` , ` "require" ` , ` "node" ` , ` "node-addons" ` and ` "default" `
631
+ conditions are defined and implemented in Node.js core,
632
+ [ as specified above] ( #conditional-exports ) .
633
+
634
+ The ` "node-addons" ` condition can be used to provide an entry point which
635
+ uses native C++ addons. However, this condition can be disabled via the
636
+ [ ` --no-addons ` flag] [ ] . When using ` "node-addons" ` , it's recommended to treat
637
+ ` "default" ` as an enhancement that provides a more universal entry point, e.g.
638
+ using WebAssembly instead of a native addon.
628
639
629
640
Other condition strings are unknown to Node.js and thus ignored by default.
630
641
Runtimes or tools other than Node.js can use them at their discretion.
@@ -1249,6 +1260,7 @@ This field defines [subpath imports][] for the current package.
1249
1260
[` "name"` ]: #packages_name
1250
1261
[` "packageManager"` ]: #packages_packagemanager
1251
1262
[` "type"` ]: #packages_type
1263
+ [` --no-addons` flag]: cli .md #-- no- addons
1252
1264
[` ERR_PACKAGE_PATH_NOT_EXPORTED` ]: errors .md #errors_err_package_path_not_exported
1253
1265
[` esm` ]: https: // github.com/standard-things/esm#readme
1254
1266
[` package.json` ]: #packages_node_js_package_json_field_definitions
0 commit comments