@@ -476,22 +476,6 @@ These CommonJS variables are not available in ES modules.
476
476
` __filename` and ` __dirname` use cases can be replicated via
477
477
[` import.meta.url` ][].
478
478
479
- #### No JSON Module Loading
480
-
481
- JSON imports are still experimental and only supported via the
482
- ` --experimental-json-modules` flag.
483
-
484
- Local JSON files can be loaded relative to ` import.meta.url` with ` fs` directly:
485
-
486
- <!-- eslint-skip -->
487
-
488
- ` ` ` js
489
- import { readFile } from ' fs/promises' ;
490
- const json = JSON .parse (await readFile (new URL (' ./dat.json' , import .meta.url)));
491
- ` ` `
492
-
493
- Alternatively ` module .createRequire ()` can be used.
494
-
495
479
#### No Native Module Loading
496
480
497
481
Native modules are not currently supported with ES module imports.
@@ -529,35 +513,19 @@ separate cache.
529
513
530
514
> Stability: 1 - Experimental
531
515
532
- Currently importing JSON modules are only supported in the ` commonjs` mode
533
- and are loaded using the CJS loader. [WHATWG JSON modules specification][] are
534
- still being standardized, and are experimentally supported by including the
535
- additional flag ` --experimental-json-modules` when running Node.js.
536
-
537
- When the ` --experimental-json-modules` flag is included, both the
538
- ` commonjs` and ` module` mode use the new experimental JSON
539
- loader. The imported JSON only exposes a ` default ` . There is no
540
- support for named exports. A cache entry is created in the CommonJS
541
- cache to avoid duplication. The same object is returned in
542
- CommonJS if the JSON module has already been imported from the
543
- same path.
544
-
545
- Assuming an ` index.mjs` with
516
+ JSON files can be referenced by ` import` :
546
517
547
518
` ` ` js
548
519
import packageConfig from ' ./package.json' assert { type : 'json ' };
549
520
` ` `
550
521
551
- The ` -- experimental- json- modules` flag is needed for the module
552
- to work.
553
-
554
- ` ` ` bash
555
- node index .mjs # fails
556
- node -- experimental- json- modules index .mjs # works
557
- ` ` `
558
-
559
522
The ` assert { type: ' json' }` syntax is mandatory; see [Import Assertions][].
560
523
524
+ The imported JSON only exposes a ` default` export. There is no support for named
525
+ exports. A cache entry is created in the CommonJS cache to avoid duplication.
526
+ The same object is returned in CommonJS if the JSON module has already been
527
+ imported from the same path.
528
+
561
529
<i id="esm_experimental_wasm_modules"></i>
562
530
563
531
## Wasm modules
@@ -1451,7 +1419,6 @@ success!
1451
1419
[Node.js Module Resolution Algorithm]: #resolver-algorithm-specification
1452
1420
[Terminology]: #terminology
1453
1421
[URL]: https:// url.spec.whatwg.org/
1454
- [WHATWG JSON modules specification]: https:// html.spec.whatwg.org/#creating-a-json-module-script
1455
1422
[`"exports"`]: packages.md#exports
1456
1423
[`"type"`]: packages.md#type
1457
1424
[`--input-type`]: cli.md#--input-typetype
0 commit comments