Skip to content

Commit

Permalink
fixup! module: unflag esm json modules
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyBooth committed Jan 31, 2022
1 parent 6f1d8a4 commit 5fe4f32
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
29 changes: 6 additions & 23 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,35 +530,19 @@ separate cache.
> Stability: 1 - Experimental
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.
When the `--experimental-json-modules` flag is included, both the
`commonjs` and `module` mode 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 is returned in
CommonJS if the JSON module has already been imported from the
same path.
Assuming an `index.mjs` with
JSON files can be referenced by `import`:
```js
import packageConfig from './package.json' assert { type: 'json' };
```
The `--experimental-json-modules` flag is needed for the module
to work.
```bash
node index.mjs # fails
node --experimental-json-modules index.mjs # works
```
The `assert { type: 'json' }` syntax is mandatory; see [Import Assertions][].
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 is returned in CommonJS if the JSON module has already been
imported from the same path.
<i id="esm_experimental_wasm_modules"></i>
## Wasm modules
Expand Down Expand Up @@ -1452,7 +1436,6 @@ success!
[Node.js Module Resolution Algorithm]: #resolver-algorithm-specification
[Terminology]: #terminology
[URL]: https://url.spec.whatwg.org/
[WHATWG JSON modules specification]: https://html.spec.whatwg.org/#creating-a-json-module-script
[`"exports"`]: packages.md#exports
[`"type"`]: packages.md#type
[`--input-type`]: cli.md#--input-typetype
Expand Down
3 changes: 1 addition & 2 deletions doc/api/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ There is the ECMAScript module loader:
`'./startup/index.js'`) must be fully specified.
* It does no extension searching. A file extension must be provided
when the specifier is a relative or absolute file URL.
* It can load JSON modules, but an import assertion is required (behind
`--experimental-json-modules` flag).
* It can load JSON modules, but an import assertion is required.
* It accepts only `.js`, `.mjs`, and `.cjs` extensions for JavaScript text
files.
* It can be used to load JavaScript CommonJS modules. Such modules
Expand Down

0 comments on commit 5fe4f32

Please sign in to comment.