@@ -61,12 +61,12 @@ Node.js will treat the following as [ES modules][] when passed to `node` as the
61
61
initial input, or when referenced by ` import ` statements or ` import() `
62
62
expressions:
63
63
64
- - Files with an ` .mjs ` extension.
64
+ * Files with an ` .mjs ` extension.
65
65
66
- - Files with a ` .js ` extension when the nearest parent ` package.json ` file
66
+ * Files with a ` .js ` extension when the nearest parent ` package.json ` file
67
67
contains a top-level [ ` "type" ` ] [ ] field with a value of ` "module" ` .
68
68
69
- - Strings passed in as an argument to ` --eval ` , or piped to ` node ` via ` STDIN ` ,
69
+ * Strings passed in as an argument to ` --eval ` , or piped to ` node ` via ` STDIN ` ,
70
70
with the flag ` --input-type=module ` .
71
71
72
72
* Code containing syntax only successfully parsed as [ ES modules] [ ] , such as
@@ -82,28 +82,28 @@ Node.js will treat the following as [CommonJS][] when passed to `node` as the
82
82
initial input, or when referenced by ` import ` statements or ` import() `
83
83
expressions:
84
84
85
- - Files with a ` .cjs ` extension.
85
+ * Files with a ` .cjs ` extension.
86
86
87
- - Files with a ` .js ` extension when the nearest parent ` package.json ` file
87
+ * Files with a ` .js ` extension when the nearest parent ` package.json ` file
88
88
contains a top-level field [ ` "type" ` ] [ ] with a value of ` "commonjs" ` .
89
89
90
- - Strings passed in as an argument to ` --eval ` or ` --print ` , or piped to ` node `
90
+ * Strings passed in as an argument to ` --eval ` or ` --print ` , or piped to ` node `
91
91
via ` STDIN ` , with the flag ` --input-type=commonjs ` .
92
92
93
93
Aside from these explicit cases, there are other cases where Node.js defaults to
94
94
one module system or the other based on the value of the
95
95
[ ` --experimental-default-type ` ] [ ] flag:
96
96
97
- - Files ending in ` .js ` or with no extension, if there is no ` package.json ` file
97
+ * Files ending in ` .js ` or with no extension, if there is no ` package.json ` file
98
98
present in the same folder or any parent folder.
99
99
100
- - Files ending in ` .js ` or with no extension, if the nearest parent
100
+ * Files ending in ` .js ` or with no extension, if the nearest parent
101
101
` package.json ` field lacks a ` "type" ` field; unless the folder is inside a
102
102
` node_modules ` folder. (Package scopes under ` node_modules ` are always treated
103
103
as CommonJS when the ` package.json ` file lacks a ` "type" ` field, regardless
104
104
of ` --experimental-default-type ` , for backward compatibility.)
105
105
106
- - Strings passed in as an argument to ` --eval ` or piped to ` node ` via ` STDIN ` ,
106
+ * Strings passed in as an argument to ` --eval ` or piped to ` node ` via ` STDIN ` ,
107
107
when ` --input-type ` is unspecified.
108
108
109
109
This flag currently defaults to ` "commonjs" ` , but it may change in the future to
@@ -159,37 +159,37 @@ Node.js has two systems for resolving a specifier and loading modules.
159
159
160
160
There is the CommonJS module loader:
161
161
162
- - It is fully synchronous.
163
- - It is responsible for handling ` require() ` calls.
164
- - It is monkey patchable.
165
- - It supports [ folders as modules] [ ] .
166
- - When resolving a specifier, if no exact match is found, it will try to add
162
+ * It is fully synchronous.
163
+ * It is responsible for handling ` require() ` calls.
164
+ * It is monkey patchable.
165
+ * It supports [ folders as modules] [ ] .
166
+ * When resolving a specifier, if no exact match is found, it will try to add
167
167
extensions (` .js ` , ` .json ` , and finally ` .node ` ) and then attempt to resolve
168
168
[ folders as modules] [ ] .
169
- - It treats ` .json ` as JSON text files.
170
- - ` .node ` files are interpreted as compiled addon modules loaded with
169
+ * It treats ` .json ` as JSON text files.
170
+ * ` .node ` files are interpreted as compiled addon modules loaded with
171
171
` process.dlopen() ` .
172
- - It treats all files that lack ` .json ` or ` .node ` extensions as JavaScript
172
+ * It treats all files that lack ` .json ` or ` .node ` extensions as JavaScript
173
173
text files.
174
- - It can only be used to [ load ECMASCript modules from CommonJS modules] [ ] if
174
+ * It can only be used to [ load ECMASCript modules from CommonJS modules] [ ] if
175
175
the module graph is synchronous (that contains no top-level ` await ` ) when
176
176
` --experimental-require-module ` is enabled.
177
177
When used to load a JavaScript text file that is not an ECMAScript module,
178
178
the file will be loaded as a CommonJS module.
179
179
180
180
There is the ECMAScript module loader:
181
181
182
- - It is asynchronous, unless it's being used to load modules for ` require() ` .
183
- - It is responsible for handling ` import ` statements and ` import() ` expressions.
184
- - It is not monkey patchable, can be customized using [ loader hooks] [ ] .
185
- - It does not support folders as modules, directory indexes (e.g.
182
+ * It is asynchronous, unless it's being used to load modules for ` require() ` .
183
+ * It is responsible for handling ` import ` statements and ` import() ` expressions.
184
+ * It is not monkey patchable, can be customized using [ loader hooks] [ ] .
185
+ * It does not support folders as modules, directory indexes (e.g.
186
186
` './startup/index.js' ` ) must be fully specified.
187
- - It does no extension searching. A file extension must be provided
187
+ * It does no extension searching. A file extension must be provided
188
188
when the specifier is a relative or absolute file URL.
189
- - It can load JSON modules, but an import type attribute is required.
190
- - It accepts only ` .js ` , ` .mjs ` , and ` .cjs ` extensions for JavaScript text
189
+ * It can load JSON modules, but an import type attribute is required.
190
+ * It accepts only ` .js ` , ` .mjs ` , and ` .cjs ` extensions for JavaScript text
191
191
files.
192
- - It can be used to load JavaScript CommonJS modules. Such modules
192
+ * It can be used to load JavaScript CommonJS modules. Such modules
193
193
are passed through the ` cjs-module-lexer ` to try to identify named exports,
194
194
which are available if they can be determined through static analysis.
195
195
Imported CommonJS modules have their URLs converted to absolute
@@ -241,12 +241,12 @@ import 'commonjs-package/src/index.mjs';
241
241
The ` .mjs ` and ` .cjs ` extensions can be used to mix types within the same
242
242
package:
243
243
244
- - Within a ` "type": "module" ` package, Node.js can be instructed to
244
+ * Within a ` "type": "module" ` package, Node.js can be instructed to
245
245
interpret a particular file as [ CommonJS] [ ] by naming it with a ` .cjs `
246
246
extension (since both ` .js ` and ` .mjs ` files are treated as ES modules within
247
247
a ` "module" ` package).
248
248
249
- - Within a ` "type": "commonjs" ` package, Node.js can be instructed to
249
+ * Within a ` "type": "commonjs" ` package, Node.js can be instructed to
250
250
interpret a particular file as an [ ES module] [ ] by naming it with an ` .mjs `
251
251
extension (since both ` .js ` and ` .cjs ` files are treated as CommonJS within a
252
252
` "commonjs" ` package).
@@ -647,25 +647,25 @@ For example, a package that wants to provide different ES module exports for
647
647
Node.js implements the following conditions, listed in order from most
648
648
specific to least specific as conditions should be defined:
649
649
650
- - ` "node-addons" ` - similar to ` "node" ` and matches for any Node.js environment.
650
+ * ` "node-addons" ` - similar to ` "node" ` and matches for any Node.js environment.
651
651
This condition can be used to provide an entry point which uses native C++
652
652
addons as opposed to an entry point which is more universal and doesn't rely
653
653
on native addons. This condition can be disabled via the
654
654
[ ` --no-addons ` flag] [ ] .
655
- - ` "node" ` - matches for any Node.js environment. Can be a CommonJS or ES
655
+ * ` "node" ` - matches for any Node.js environment. Can be a CommonJS or ES
656
656
module file. _ In most cases explicitly calling out the Node.js platform is
657
657
not necessary._
658
- - ` "import" ` - matches when the package is loaded via ` import ` or
658
+ * ` "import" ` - matches when the package is loaded via ` import ` or
659
659
` import() ` , or via any top-level import or resolve operation by the
660
660
ECMAScript module loader. Applies regardless of the module format of the
661
661
target file. _ Always mutually exclusive with ` "require" ` ._
662
- - ` "require" ` - matches when the package is loaded via ` require() ` . The
662
+ * ` "require" ` - matches when the package is loaded via ` require() ` . The
663
663
referenced file should be loadable with ` require() ` although the condition
664
664
matches regardless of the module format of the target file. Expected
665
665
formats include CommonJS, JSON, native addons, and ES modules
666
666
if ` --experimental-require-module ` is enabled. _ Always mutually
667
667
exclusive with ` "import" ` ._
668
- - ` "default" ` - the generic fallback that always matches. Can be a CommonJS
668
+ * ` "default" ` - the generic fallback that always matches. Can be a CommonJS
669
669
or ES module file. _ This condition should always come last._
670
670
671
671
Within the [ ` "exports" ` ] [ ] object, key order is significant. During condition
@@ -766,14 +766,14 @@ Since custom package conditions require clear definitions to ensure correct
766
766
usage, a list of common known package conditions and their strict definitions
767
767
is provided below to assist with ecosystem coordination.
768
768
769
- - ` "types" ` - can be used by typing systems to resolve the typing file for
769
+ * ` "types" ` - can be used by typing systems to resolve the typing file for
770
770
the given export. _ This condition should always be included first._
771
- - ` "browser" ` - any web browser environment.
772
- - ` "development" ` - can be used to define a development-only environment
771
+ * ` "browser" ` - any web browser environment.
772
+ * ` "development" ` - can be used to define a development-only environment
773
773
entry point, for example to provide additional debugging context such as
774
774
better error messages when running in a development mode. _ Must always be
775
775
mutually exclusive with ` "production" ` ._
776
- - ` "production" ` - can be used to define a production environment entry
776
+ * ` "production" ` - can be used to define a production environment entry
777
777
point. _ Must always be mutually exclusive with ` "development" ` ._
778
778
779
779
For other runtimes, platform-specific condition key definitions are maintained
@@ -783,16 +783,16 @@ New conditions definitions may be added to this list by creating a pull request
783
783
to the [ Node.js documentation for this section] [ ] . The requirements for listing
784
784
a new condition definition here are that:
785
785
786
- - The definition should be clear and unambiguous for all implementers.
787
- - The use case for why the condition is needed should be clearly justified.
788
- - There should exist sufficient existing implementation usage.
789
- - The condition name should not conflict with another condition definition or
786
+ * The definition should be clear and unambiguous for all implementers.
787
+ * The use case for why the condition is needed should be clearly justified.
788
+ * There should exist sufficient existing implementation usage.
789
+ * The condition name should not conflict with another condition definition or
790
790
condition in wide usage.
791
- - The listing of the condition definition should provide a coordination
791
+ * The listing of the condition definition should provide a coordination
792
792
benefit to the ecosystem that wouldn't otherwise be possible. For example,
793
793
this would not necessarily be the case for company-specific or
794
794
application-specific conditions.
795
- - The condition should be such that a Node.js user would expect it to be in
795
+ * The condition should be such that a Node.js user would expect it to be in
796
796
Node.js core documentation. The ` "types" ` condition is a good example: It
797
797
doesn't really belong in the [ Runtime Keys] [ ] proposal but is a good fit
798
798
here in the Node.js docs.
@@ -1044,17 +1044,17 @@ additional fields which are ignored by Node.js and not documented here.
1044
1044
1045
1045
The following fields in ` package.json ` files are used in Node.js:
1046
1046
1047
- - [ ` "name" ` ] [ ] - Relevant when using named imports within a package. Also used
1047
+ * [ ` "name" ` ] [ ] - Relevant when using named imports within a package. Also used
1048
1048
by package managers as the name of the package.
1049
- - [ ` "main" ` ] [ ] - The default module when loading the package, if exports is not
1049
+ * [ ` "main" ` ] [ ] - The default module when loading the package, if exports is not
1050
1050
specified, and in versions of Node.js prior to the introduction of exports.
1051
- - [ ` "packageManager" ` ] [ ] - The package manager recommended when contributing to
1051
+ * [ ` "packageManager" ` ] [ ] - The package manager recommended when contributing to
1052
1052
the package. Leveraged by the [ Corepack] [ ] shims.
1053
- - [ ` "type" ` ] [ ] - The package type determining whether to load ` .js ` files as
1053
+ * [ ` "type" ` ] [ ] - The package type determining whether to load ` .js ` files as
1054
1054
CommonJS or ES modules.
1055
- - [ ` "exports" ` ] [ ] - Package exports and conditional exports. When present,
1055
+ * [ ` "exports" ` ] [ ] - Package exports and conditional exports. When present,
1056
1056
limits which submodules can be loaded from within the package.
1057
- - [ ` "imports" ` ] [ ] - Package imports, for use by modules within the package
1057
+ * [ ` "imports" ` ] [ ] - Package imports, for use by modules within the package
1058
1058
itself.
1059
1059
1060
1060
### ` "name" `
@@ -1071,7 +1071,7 @@ changes:
1071
1071
description: Remove the `--experimental-resolve-self` option.
1072
1072
-->
1073
1073
1074
- - Type: {string}
1074
+ * Type: {string}
1075
1075
1076
1076
``` json
1077
1077
{
@@ -1092,7 +1092,7 @@ The `"name"` field can be used in addition to the [`"exports"`][] field to
1092
1092
added: v0.4.0
1093
1093
-->
1094
1094
1095
- - Type: {string}
1095
+ * Type: {string}
1096
1096
1097
1097
``` json
1098
1098
{
@@ -1124,7 +1124,7 @@ added:
1124
1124
1125
1125
> Stability: 1 - Experimental
1126
1126
1127
- - Type: {string}
1127
+ * Type: {string}
1128
1128
1129
1129
``` json
1130
1130
{
@@ -1153,7 +1153,7 @@ changes:
1153
1153
description: Unflag `--experimental-modules`.
1154
1154
-->
1155
1155
1156
- - Type: {string}
1156
+ * Type: {string}
1157
1157
1158
1158
The ` "type" ` field defines the module format that Node.js uses for all
1159
1159
` .js ` files that have that ` package.json ` file as their nearest parent.
@@ -1164,7 +1164,7 @@ Files ending with `.js` are loaded as ES modules when the nearest parent
1164
1164
1165
1165
The nearest parent ` package.json ` is defined as the first ` package.json ` found
1166
1166
when searching in the current folder, that folder's parent, and so on up
1167
- until a node_modules folder or the volume root is reached.
1167
+ until a node \_ modules folder or the volume root is reached.
1168
1168
1169
1169
``` json
1170
1170
// package.json
@@ -1226,7 +1226,7 @@ changes:
1226
1226
description: Implement conditional exports.
1227
1227
-->
1228
1228
1229
- - Type: {Object} | {string} | {string\[ ] }
1229
+ * Type: {Object} | {string} | {string\[ ] }
1230
1230
1231
1231
``` json
1232
1232
{
@@ -1255,7 +1255,7 @@ added:
1255
1255
- v12.19.0
1256
1256
-->
1257
1257
1258
- - Type: {Object}
1258
+ * Type: {Object}
1259
1259
1260
1260
``` json
1261
1261
// package.json
0 commit comments