Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! module: unflag esm json modules
  • Loading branch information
GeoffreyBooth committed Jan 31, 2022
commit b09ba2c25a053184711844d3fbcd6f0a55040e00
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
Comment thread
GeoffreyBooth marked this conversation as resolved.
Outdated
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.
Comment thread
GeoffreyBooth marked this conversation as resolved.

<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