@@ -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
@@ -78,7 +75,7 @@ until the root of the volume is reached.
7875
7976``` sh
8077# 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
8279```
8380
8481If 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
113110project’s dependencies have their own package scopes. A ` package.json ` lacking a
114111` "type" ` field is treated as if it contained ` "type": "commonjs" ` .
115112
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.
119115
120116``` js
121117// 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
168164` --input-type=module ` flag is set.
169165
170166``` 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);"
173168
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
176170```
177171
178172For completeness there is also ` --input-type=commonjs ` , for explicitly running
@@ -1004,8 +998,8 @@ The `--experimental-json-modules` flag is needed for the module
1004998to work .
1005999
10061000` ` ` 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
10091003` ` `
10101004
10111005## Experimental Wasm Modules
@@ -1027,7 +1021,7 @@ console.log(M);
10271021executed under :
10281022
10291023` ` ` bash
1030- node --experimental-modules --experimental- wasm-modules index.mjs
1024+ node --experimental-wasm-modules index.mjs
10311025` ` `
10321026
10331027would provide the exports interface for the instantiation of ` module.wasm` .
@@ -1154,7 +1148,7 @@ export async function getSource(url, context, defaultGetSource) {
11541148#### < code > transformSource < / code > hook
11551149
11561150` ` ` console
1157- NODE_OPTIONS='--experimental-modules --experimental- loader ./custom-loader.mjs' node x.js
1151+ NODE_OPTIONS='--experimental-loader ./custom-loader.mjs' node x.js
11581152` ` `
11591153
11601154> Note : The loaders API is being redesigned . This hook may disappear or its
@@ -1712,11 +1706,11 @@ automatic extension resolution and importing from directories that include an
17121706index file use the `node` mode.
17131707
17141708```bash
1715- $ node --experimental-modules index.mjs
1709+ $ node index.mjs
17161710success!
1717- $ node --experimental-modules index #Failure!
1711+ $ node index # Failure!
17181712Error: Cannot find module
1719- $ node --experimental-modules --experimental- specifier-resolution=node index
1713+ $ node --experimental-specifier-resolution=node index
17201714success!
17211715```
17221716
0 commit comments