@@ -335,8 +335,8 @@ Node.js and the browser can be written:
335335 " main" : " ./index.js" ,
336336 " exports" : {
337337 " ./feature" : {
338- " browser " : " ./feature-browser .js" ,
339- " default " : " ./feature-default .js"
338+ " import " : " ./feature-default .js" ,
339+ " browser " : " ./feature-browser .js"
340340 }
341341 }
342342}
@@ -347,16 +347,24 @@ will be used as the final fallback.
347347
348348The conditions supported in Node.js are matched in the following order:
349349
350- 1 . ` "require" ` - matched when the package is loaded via ` require() ` .
351- _ This is currently only supported behind the
352- ` --experimental-conditional-exports ` flag._
353- 2 . ` "node" ` - matched for any Node.js environment. Can be a CommonJS or ES
350+ 1 . ` "node" ` - matched for any Node.js environment. Can be a CommonJS or ES
354351 module file. _ This is currently only supported behind the
355- ` --experimental-conditional-exports ` flag._
356- 3 . ` "default" ` - the generic fallback that will always match if no other
352+ ` --experimental-conditional-exports ` flag._
353+ 2 . ` "require" ` - matched when the package is loaded via ` require() ` .
354+ _ This is currently only supported behind the
355+ ` --experimental-conditional-exports ` flag._
356+ 3 . ` "import" ` - matched when the package is loaded via ` import ` or
357+ ` 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._
360+ 4 . ` "default" ` - the generic fallback that will always match if no other
357361 more specific condition is matched first. Can be a CommonJS or ES module
358362 file.
359363
364+ > Setting any of the above flagged conditions for a published package is not
365+ > recommended until they are unflagged to avoid breaking changes to packages in
366+ > future.
367+
360368Using the ` "require" ` condition it is possible to define a package that will
361369have a different exported value for CommonJS and ES modules, which can be a
362370hazard in that it can result in having two separate instances of the same
@@ -400,8 +408,8 @@ from exports subpaths.
400408{
401409 " exports" : {
402410 " ." : {
403- " require " : " ./main.cjs " ,
404- " default " : " ./main.js "
411+ " import " : " ./main.js " ,
412+ " require " : " ./main.cjs "
405413 }
406414 }
407415}
@@ -413,8 +421,8 @@ can be written:
413421``` js
414422{
415423 " exports" : {
416- " require " : " ./main.cjs " ,
417- " default " : " ./main.js "
424+ " import " : " ./main.js " ,
425+ " require " : " ./main.cjs "
418426 }
419427}
420428```
@@ -428,8 +436,8 @@ thrown:
428436 // Throws on resolution!
429437 " exports" : {
430438 " ./feature" : " ./lib/feature.js" ,
431- " require " : " ./main.cjs " ,
432- " default " : " ./main.js "
439+ " import " : " ./main.js " ,
440+ " require " : " ./main.cjs "
433441 }
434442}
435443```
@@ -514,9 +522,8 @@ ES module wrapper is used for `import` and the CommonJS entry point for
514522` require ` .
515523
516524> Note: While ` --experimental-conditional-exports ` is flagged, a package
517- > using this pattern will throw when loaded via ` require() ` in modern
518- > Node.js, unless package consumers use the ` --experimental-conditional-exports `
519- > flag.
525+ > using this pattern will throw when loaded unless package consumers use the
526+ > ` --experimental-conditional-exports ` flag.
520527
521528<!-- eslint-skip -->
522529``` js
@@ -526,7 +533,7 @@ ES module wrapper is used for `import` and the CommonJS entry point for
526533 " main" : " ./index.cjs" ,
527534 " exports" : {
528535 " require" : " ./index.cjs" ,
529- " default " : " ./wrapper.mjs"
536+ " import " : " ./wrapper.mjs"
530537 }
531538}
532539```
@@ -611,8 +618,8 @@ CommonJS and ES module entry points directly (requires
611618 " type" : " module" ,
612619 " main" : " ./index.cjs" ,
613620 " exports" : {
614- " require " : " ./index.cjs " ,
615- " default " : " ./index.mjs "
621+ " import " : " ./index.mjs " ,
622+ " require " : " ./index.cjs "
616623 }
617624}
618625```
@@ -1152,7 +1159,7 @@ of these top-level routines unless stated otherwise.
11521159_isMain_ is **true** when resolving the Node.js application entry point.
11531160
11541161_defaultEnv_ is the conditional environment name priority array,
1155- ` [" node" , " default " ]` .
1162+ ` [" node" , " import " ]` .
11561163
11571164<details>
11581165<summary>Resolver algorithm specification</summary>
0 commit comments