@@ -27,12 +27,9 @@ specifier resolution, and default behavior.
27
27
28
28
<!-- type=misc -->
29
29
30
- The ` --experimental-modules ` flag can be used to enable support for
31
- ECMAScript modules (ES modules).
32
-
33
- Once enabled, Node.js will treat the following as ES modules when passed to
34
- ` node ` as the initial input, or when referenced by ` import ` statements within
35
- ES module code:
30
+ Experimental support for ECMAScript modules is enabled by default.
31
+ Node.js will treat the following as ES modules when passed to ` node ` as the
32
+ initial input, or when referenced by ` import ` statements within ES module code:
36
33
37
34
* Files ending in ` .mjs ` .
38
35
@@ -78,7 +75,7 @@ until the root of the volume is reached.
78
75
79
76
``` sh
80
77
# In same folder as above package.json
81
- node --experimental-modules my-app.js # Runs as ES module
78
+ node my-app.js # Runs as ES module
82
79
```
83
80
84
81
If the nearest parent ` package.json ` lacks a ` "type" ` field, or contains
@@ -113,9 +110,8 @@ project’s `node_modules` folder contains its own `package.json` file, so each
113
110
project’s dependencies have their own package scopes. A ` package.json ` lacking a
114
111
` "type" ` field is treated as if it contained ` "type": "commonjs" ` .
115
112
116
- The package scope applies not only to initial entry points (`node
117
- --experimental-modules my-app.js` ) but also to files referenced by ` import`
118
- statements and ` import() ` expressions.
113
+ The package scope applies not only to initial entry points (` node my-app.js ` )
114
+ but also to files referenced by ` import ` statements and ` import() ` expressions.
119
115
120
116
``` js
121
117
// my-app.js, in an ES module package scope because there is a package.json
@@ -168,11 +164,9 @@ piped to `node` via `STDIN`, will be treated as ES modules when the
168
164
` --input-type=module ` flag is set.
169
165
170
166
``` sh
171
- node --experimental-modules --input-type=module --eval \
172
- " import { sep } from 'path'; console.log(sep);"
167
+ node --input-type=module --eval " import { sep } from 'path'; console.log(sep);"
173
168
174
- echo " import { sep } from 'path'; console.log(sep);" | \
175
- node --experimental-modules --input-type=module
169
+ echo " import { sep } from 'path'; console.log(sep);" | node --input-type=module
176
170
```
177
171
178
172
For completeness there is also ` --input-type=commonjs ` , for explicitly running
@@ -1004,8 +998,8 @@ The `--experimental-json-modules` flag is needed for the module
1004
998
to work .
1005
999
1006
1000
` ` ` bash
1007
- node --experimental-modules index.mjs # fails
1008
- node --experimental-modules --experimental- json-modules index.mjs # works
1001
+ node index.mjs # fails
1002
+ node --experimental-json-modules index.mjs # works
1009
1003
` ` `
1010
1004
1011
1005
## Experimental Wasm Modules
@@ -1027,7 +1021,7 @@ console.log(M);
1027
1021
executed under :
1028
1022
1029
1023
` ` ` bash
1030
- node --experimental-modules --experimental- wasm-modules index.mjs
1024
+ node --experimental-wasm-modules index.mjs
1031
1025
` ` `
1032
1026
1033
1027
would provide the exports interface for the instantiation of ` module.wasm` .
@@ -1173,7 +1167,7 @@ export async function getSource(url, context, defaultGetSource) {
1173
1167
#### <code>transformSource</code> hook
1174
1168
1175
1169
` ` ` console
1176
- NODE_OPTIONS = ' --experimental-modules --experimental- loader ./custom-loader.mjs' node x .js
1170
+ NODE_OPTIONS = ' --experimental-loader ./custom-loader.mjs' node x .js
1177
1171
` ` `
1178
1172
1179
1173
> Note: The loaders API is being redesigned. This hook may disappear or its
@@ -1733,11 +1727,11 @@ automatic extension resolution and importing from directories that include an
1733
1727
index file use the `node` mode.
1734
1728
1735
1729
```bash
1736
- $ node --experimental-modules index.mjs
1730
+ $ node index.mjs
1737
1731
success!
1738
- $ node --experimental-modules index #Failure!
1732
+ $ node index # Failure!
1739
1733
Error: Cannot find module
1740
- $ node --experimental-modules --experimental- specifier-resolution=node index
1734
+ $ node --experimental-specifier-resolution=node index
1741
1735
success!
1742
1736
```
1743
1737
0 commit comments