@@ -355,21 +355,14 @@ The conditions supported in Node.js condition matching:
355355 or ES module file.
356356* ` "import" ` - matched when the package is loaded via ` import ` or
357357 ` import() ` . Can be any module format, this field does not set the type
358- interpretation. _ This is currently only supported behind the
359- ` --experimental-conditional-exports ` flag._
358+ interpretation.
360359* ` "node" ` - matched for any Node.js environment. Can be a CommonJS or ES
361- module file. _ This is currently only supported behind the
362- ` --experimental-conditional-exports ` flag._
360+ module file.
363361* ` "require" ` - matched when the package is loaded via ` require() ` .
364- _ This is currently only supported behind the
365- ` --experimental-conditional-exports ` flag._
366362
367363Condition matching is applied in object order from first to last within the
368364` "exports" ` object.
369365
370- > Setting the above conditions for a published package is not recommended until
371- > conditional exports have been unflagged to avoid breaking changes to packages.
372-
373366Using the ` "require" ` condition it is possible to define a package that will
374367have a different exported value for CommonJS and ES modules, which can be a
375368hazard in that it can result in having two separate instances of the same
@@ -462,10 +455,10 @@ ignores) the top-level `"module"` field.
462455Node.js can now run ES module entry points, and a package can contain both
463456CommonJS and ES module entry points (either via separate specifiers such as
464457` 'pkg' ` and ` 'pkg/es-module' ` , or both at the same specifier via [ Conditional
465- Exports] [ ] with the ` --experimental-conditional-exports ` flag). Unlike in the
466- scenario where ` " module" ` is only used by bundlers, or ES module files are
467- transpiled into CommonJS on the fly before evaluation by Node.js, the files
468- referenced by the ES module entry point are evaluated as ES modules.
458+ Exports] [ ] ). Unlike in the scenario where ` "module" ` is only used by bundlers,
459+ or ES module files are transpiled into CommonJS on the fly before evaluation by
460+ Node.js, the files referenced by the ES module entry point are evaluated as ES
461+ modules.
469462
470463#### Dual Package Hazard
471464
@@ -524,13 +517,8 @@ following conditions:
524517
525518Write the package in CommonJS or transpile ES module sources into CommonJS, and
526519create an ES module wrapper file that defines the named exports. Using
527- [ Conditional Exports] [ ] via the ` --experimental-conditional-exports ` flag, the
528- ES module wrapper is used for ` import ` and the CommonJS entry point for
529- ` require ` .
530-
531- > Note: While ` --experimental-conditional-exports ` is flagged, a package
532- > using this pattern will throw when loaded unless package consumers use the
533- > ` --experimental-conditional-exports ` flag.
520+ [ Conditional Exports] [ ] , the ES module wrapper is used for ` import ` and the
521+ CommonJS entry point for ` require ` .
534522
535523<!-- eslint-skip -->
536524``` js
@@ -586,13 +574,13 @@ This approach is appropriate for any of the following use cases:
586574* The package stores internal state, and the package author would prefer not to
587575 refactor the package to isolate its state management. See the next section.
588576
589- A variant of this approach not requiring ` --experimental- conditional- exports`
590- for consumers could be to add an export, e.g. ` "./module" ` , to point to an
591- all-ES module-syntax version of the package. This could be used via `import
592- 'pkg/module'` by users who are certain that the CommonJS version will not be
593- loaded anywhere in the application, such as by dependencies; or if the CommonJS
594- version can be loaded but doesn’t affect the ES module version (for example,
595- because the package is stateless):
577+ A variant of this approach not requiring conditional exports for consumers could
578+ be to add an export, e.g. ` "./module" ` , to point to an all-ES module-syntax
579+ version of the package. This could be used via ` import 'pkg/module' ` by users
580+ who are certain that the CommonJS version will not be loaded anywhere in the
581+ application, such as by dependencies; or if the CommonJS version can be loaded
582+ but doesn’t affect the ES module version (for example, because the package is
583+ stateless):
596584
597585<!-- eslint-skip -->
598586``` js
@@ -607,16 +595,10 @@ because the package is stateless):
607595}
608596```
609597
610- If the ` --experimental-conditional-exports ` flag is dropped and therefore
611- [ Conditional Exports] [ ] become available without a flag, this variant could be
612- easily updated to use conditional exports by adding conditions to the ` "." `
613- path; while keeping ` "./module" ` for backward compatibility.
614-
615598##### Approach #2 : Isolate State
616599
617600The most straightforward ` package.json ` would be one that defines the separate
618- CommonJS and ES module entry points directly (requires
619- ` --experimental-conditional-exports ` ):
601+ CommonJS and ES module entry points directly:
620602
621603<!-- eslint-skip -->
622604``` js
@@ -701,8 +683,8 @@ Even with isolated state, there is still the cost of possible extra code
701683execution between the CommonJS and ES module versions of a package .
702684
703685As with the previous approach, a variant of this approach not requiring
704- ` --experimental- conditional- exports` for consumers could be to add an export ,
705- e . g . ` "./module"` , to point to an all- ES module - syntax version of the package:
686+ conditional exports for consumers could be to add an export , e . g .
687+ ` "./module"` , to point to an all- ES module - syntax version of the package:
706688
707689<!-- eslint- skip -->
708690` ` ` js
@@ -717,11 +699,6 @@ e.g. `"./module"`, to point to an all-ES module-syntax version of the package:
717699}
718700` ` `
719701
720- If the ` --experimental-conditional-exports` flag is dropped and therefore
721- [Conditional Exports][] become available without a flag, this variant could be
722- easily updated to use conditional exports by adding conditions to the ` "."`
723- path; while keeping ` "./module"` for backward compatibility.
724-
725702## ` import` Specifiers
726703
727704### Terminology
0 commit comments