@@ -27,12 +27,9 @@ specifier resolution, and default behavior.
2727
2828<!-- type=misc -->
2929
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:
3633
3734* Files ending in ` .mjs ` .
3835
@@ -80,7 +77,7 @@ until the root of the volume is reached.
8077
8178``` sh
8279# In same folder as above package.json
83- node --experimental-modules my-app.js # Runs as ES module
80+ node my-app.js # Runs as ES module
8481```
8582
8683If the nearest parent ` package.json ` lacks a ` "type" ` field, or contains
@@ -114,9 +111,8 @@ own `package.json` file, so each project’s dependencies have their own package
114111scopes. A ` package.json ` lacking a ` "type" ` field is treated as if it contained
115112` "type": "commonjs" ` .
116113
117- The package scope applies not only to initial entry points (`node
118- --experimental-modules my-app.js` ) but also to files referenced by ` import`
119- statements and ` import() ` expressions.
114+ The package scope applies not only to initial entry points (` node my-app.js ` )
115+ but also to files referenced by ` import ` statements and ` import() ` expressions.
120116
121117``` js
122118// my-app.js, in an ES module package scope because there is a package.json
@@ -169,11 +165,9 @@ piped to `node` via `STDIN`, will be treated as ES modules when the
169165` --input-type=module ` flag is set.
170166
171167``` sh
172- node --experimental-modules --input-type=module --eval \
173- " import { sep } from 'path'; console.log(sep);"
168+ node --input-type=module --eval " import { sep } from 'path'; console.log(sep);"
174169
175- echo " import { sep } from 'path'; console.log(sep);" | \
176- node --experimental-modules --input-type=module
170+ echo " import { sep } from 'path'; console.log(sep);" | node --input-type=module
177171```
178172
179173For completeness there is also ` --input-type=commonjs ` , for explicitly running
@@ -927,8 +921,8 @@ The `--experimental-json-modules` flag is needed for the module
927921to work.
928922
929923` ` ` bash
930- node --experimental-modules index.mjs # fails
931- node --experimental-modules --experimental- json-modules index.mjs # works
924+ node index.mjs # fails
925+ node --experimental-json-modules index.mjs # works
932926` ` `
933927
934928## Experimental Wasm Modules
@@ -950,7 +944,7 @@ console.log(M);
950944executed under:
951945
952946` ` ` bash
953- node --experimental-modules --experimental- wasm-modules index.mjs
947+ node --experimental-wasm-modules index.mjs
954948` ` `
955949
956950would provide the exports interface for the instantiation of ` module.wasm` .
@@ -1061,7 +1055,7 @@ export async function resolve(specifier,
10611055With this loader, running:
10621056
10631057` ` ` console
1064- NODE_OPTIONS = ' --experimental-modules --experimental- loader ./custom-loader.mjs' node x .js
1058+ NODE_OPTIONS = ' --experimental-loader ./custom-loader.mjs' node x .js
10651059` ` `
10661060
10671061would load the module ` x .js ` as an ES module with relative resolution support
@@ -1352,11 +1346,11 @@ automatic extension resolution and importing from directories that include an
13521346index file use the ` node` mode.
13531347
13541348` ` ` bash
1355- $ node -- experimental - modules index .mjs
1349+ $ node index .mjs
13561350success!
1357- $ node -- experimental - modules index #Failure!
1351+ $ node index # Failure!
13581352Error : Cannot find module
1359- $ node -- experimental - modules -- es- module - specifier- resolution= node index
1353+ $ node -- es- module - specifier- resolution= node index
13601354success!
13611355` ` `
13621356
0 commit comments