summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorGuy Bedford <guybedford@gmail.com>2019-09-28 15:01:23 -0400
committerRich Trott <rtrott@gmail.com>2019-10-08 21:18:04 -0700
commitc0437d2633fb523fbc97deb3f1731bbefa4a2e90 (patch)
tree853bac233e5c0b27ae7b8ccd92585c5667dfd4b7 /doc
parentcbd8d715b2286e5726e6988921f5c870cbf74127 (diff)
downloadandroid-node-v8-c0437d2633fb523fbc97deb3f1731bbefa4a2e90.tar.gz
android-node-v8-c0437d2633fb523fbc97deb3f1731bbefa4a2e90.tar.bz2
android-node-v8-c0437d2633fb523fbc97deb3f1731bbefa4a2e90.zip
Revert "esm: remove experimental status from JSON modules"
This reverts commit ec8776da6fa77628e12718bb38cee687303d4137. PR-URL: https://github.com/nodejs/node/pull/29754 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/cli.md8
-rw-r--r--doc/api/esm.md19
-rw-r--r--doc/node.13
3 files changed, 27 insertions, 3 deletions
diff --git a/doc/api/cli.md b/doc/api/cli.md
index e0c2573882..df7a6362ac 100644
--- a/doc/api/cli.md
+++ b/doc/api/cli.md
@@ -165,6 +165,13 @@ added: v12.7.0
Enable experimental resolution using the `exports` field in `package.json`.
+### `--experimental-json-modules`
+<!-- YAML
+added: v12.9.0
+-->
+
+Enable experimental JSON support for the ES Module loader.
+
### `--experimental-modules`
<!-- YAML
added: v8.5.0
@@ -992,6 +999,7 @@ Node.js options that are allowed are:
* `--enable-source-maps`
* `--es-module-specifier-resolution`
* `--experimental-exports`
+* `--experimental-json-modules`
* `--experimental-loader`
* `--experimental-modules`
* `--experimental-policy`
diff --git a/doc/api/esm.md b/doc/api/esm.md
index e0a548f042..951ce41819 100644
--- a/doc/api/esm.md
+++ b/doc/api/esm.md
@@ -587,11 +587,16 @@ syncBuiltinESMExports();
fs.readFileSync === readFileSync;
```
-## JSON Modules
+## Experimental JSON Modules
-JSON modules follow the [WHATWG JSON modules specification][].
+Currently importing JSON modules are only supported in the `commonjs` mode
+and are loaded using the CJS loader. [WHATWG JSON modules specification][] are
+still being standardized, and are experimentally supported by including the
+additional flag `--experimental-json-modules` when running Node.js.
-The imported JSON only exposes a `default`. There is no
+When the `--experimental-json-modules` flag is included both the
+`commonjs` and `module` mode will use the new experimental JSON
+loader. The imported JSON only exposes a `default`, there is no
support for named exports. A cache entry is created in the CommonJS
cache, to avoid duplication. The same object will be returned in
CommonJS if the JSON module has already been imported from the
@@ -604,6 +609,14 @@ Assuming an `index.mjs` with
import packageConfig from './package.json';
```
+The `--experimental-json-modules` flag is needed for the module
+to work.
+
+```bash
+node --experimental-modules index.mjs # fails
+node --experimental-modules --experimental-json-modules index.mjs # works
+```
+
## Experimental Wasm Modules
Importing Web Assembly modules is supported under the
diff --git a/doc/node.1 b/doc/node.1
index 2b7e3dc429..7f786a05c6 100644
--- a/doc/node.1
+++ b/doc/node.1
@@ -108,6 +108,9 @@ Requires Node.js to be built with
.It Fl -es-module-specifier-resolution
Select extension resolution algorithm for ES Modules; either 'explicit' (default) or 'node'
.
+.It Fl -experimental-json-modules
+Enable experimental JSON interop support for the ES Module loader.
+.
.It Fl -experimental-modules
Enable experimental ES module support and caching modules.
.