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