@@ -477,6 +477,11 @@ Node.js implements the following conditions:
477477* ` "node" ` - matches for any Node.js environment. Can be a CommonJS or ES
478478 module file. _ This condition should always come after ` "import" ` or
479479 ` "require" ` ._
480+ * ` "node-addons" ` - similar to ` "node" ` and matches for any Node.js environment.
481+ This condition can be used to provide an entry point which uses native C++
482+ addons as opposed to an entry point which is more universal and doesn't rely
483+ on native addons. This condition can be disabled via the
484+ [ ` --no-addons ` flag] [ ] .
480485* ` "default" ` - the generic fallback that always matches. Can be a CommonJS
481486 or ES module file. _ This condition should always come last._
482487
@@ -555,17 +560,23 @@ node --conditions=development main.js
555560```
556561
557562which would then resolve the ` "development" ` condition in package imports and
558- exports, while resolving the existing ` "node" ` , ` "default " ` , ` "import " ` , and
559- ` "require" ` conditions as appropriate.
563+ exports, while resolving the existing ` "node" ` , ` "node-addons " ` , ` "default " ` ,
564+ ` "import" ` , and ` " require"` conditions as appropriate.
560565
561566Any number of custom conditions can be set with repeat flags.
562567
563568### Conditions Definitions
564569
565- The ` "import" ` , ` "require" ` , ` "node" ` and ` "default" ` conditions are defined
566- and implemented in Node.js core,
570+ The ` "import" ` , ` "require" ` , ` "node" ` , ` "node-addons" ` and ` "default" `
571+ conditions are defined and implemented in Node.js core,
567572[ as specified above] ( #packages_conditional_exports ) .
568573
574+ The ` "node-addons" ` condition can be used to provide an entry point which
575+ uses native C++ addons. However, this condition can be disabled via the
576+ [ ` --no-addons ` flag] [ ] . When using ` "node-addons" ` , it's recommended to treat
577+ ` "default" ` as an enhancement that provides a more universal entry point, e.g.
578+ using WebAssembly instead of a native addon.
579+
569580Other condition strings are unknown to Node.js and thus ignored by default.
570581Runtimes or tools other than Node.js can use them at their discretion.
571582
@@ -1161,6 +1172,7 @@ This field defines [subpath imports][] for the current package.
11611172[` "main"` ]: #packages_main
11621173[` "name"` ]: #packages_name
11631174[` "type"` ]: #packages_type
1175+ [` --no-addons` flag]: cli .md #cli_no_addons
11641176[` ERR_PACKAGE_PATH_NOT_EXPORTED` ]: errors .md #errors_err_package_path_not_exported
11651177[` esm` ]: https: // github.com/standard-things/esm#readme
11661178[` package.json` ]: #packages_node_js_package_json_field_definitions
0 commit comments