diff options
Diffstat (limited to 'doc/api/esm.md')
-rw-r--r-- | doc/api/esm.md | 19 |
1 files changed, 16 insertions, 3 deletions
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 |