@@ -329,8 +329,8 @@ Node.js and the browser can be written:
329329 " main" : " ./index.js" ,
330330 " exports" : {
331331 " ./feature" : {
332- " browser " : " ./feature-browser .js" ,
333- " default " : " ./feature-default .js"
332+ " import " : " ./feature-default .js" ,
333+ " browser " : " ./feature-browser .js"
334334 }
335335 }
336336}
@@ -341,16 +341,24 @@ will be used as the final fallback.
341341
342342The conditions supported in Node.js are matched in the following order:
343343
344- 1 . ` "require" ` - matched when the package is loaded via ` require() ` .
345- _ This is currently only supported behind the
346- ` --experimental-conditional-exports ` flag._
347- 2 . ` "node" ` - matched for any Node.js environment. Can be a CommonJS or ES
344+ 1 . ` "node" ` - matched for any Node.js environment. Can be a CommonJS or ES
348345 module file. _ This is currently only supported behind the
349- ` --experimental-conditional-exports ` flag._
350- 3 . ` "default" ` - the generic fallback that will always match if no other
346+ ` --experimental-conditional-exports ` flag._
347+ 2 . ` "require" ` - matched when the package is loaded via ` require() ` .
348+ _ This is currently only supported behind the
349+ ` --experimental-conditional-exports ` flag._
350+ 3 . ` "import" ` - matched when the package is loaded via ` import ` or
351+ ` import() ` . Can be any module format, this field does not set the type
352+ interpretation. _ This is currently only supported behind the
353+ ` --experimental-conditional-exports ` flag._
354+ 4 . ` "default" ` - the generic fallback that will always match if no other
351355 more specific condition is matched first. Can be a CommonJS or ES module
352356 file.
353357
358+ > Setting any of the above flagged conditions for a published package is not
359+ > recommended until they are unflagged to avoid breaking changes to packages in
360+ > future.
361+
354362Using the ` "require" ` condition it is possible to define a package that will
355363have a different exported value for CommonJS and ES modules, which can be a
356364hazard in that it can result in having two separate instances of the same
@@ -394,8 +402,8 @@ from exports subpaths.
394402{
395403 " exports" : {
396404 " ." : {
397- " require " : " ./main.cjs " ,
398- " default " : " ./main.js "
405+ " import " : " ./main.js " ,
406+ " require " : " ./main.cjs "
399407 }
400408 }
401409}
@@ -407,8 +415,8 @@ can be written:
407415``` js
408416{
409417 " exports" : {
410- " require " : " ./main.cjs " ,
411- " default " : " ./main.js "
418+ " import " : " ./main.js " ,
419+ " require " : " ./main.cjs "
412420 }
413421}
414422```
@@ -422,8 +430,8 @@ thrown:
422430 // Throws on resolution!
423431 " exports" : {
424432 " ./feature" : " ./lib/feature.js" ,
425- " require " : " ./main.cjs " ,
426- " default " : " ./main.js "
433+ " import " : " ./main.js " ,
434+ " require " : " ./main.cjs "
427435 }
428436}
429437```
@@ -508,9 +516,8 @@ ES module wrapper is used for `import` and the CommonJS entry point for
508516` require ` .
509517
510518> Note: While ` --experimental-conditional-exports ` is flagged, a package
511- > using this pattern will throw when loaded via ` require() ` in modern
512- > Node.js, unless package consumers use the ` --experimental-conditional-exports `
513- > flag.
519+ > using this pattern will throw when loaded unless package consumers use the
520+ > ` --experimental-conditional-exports ` flag.
514521
515522<!-- eslint-skip -->
516523``` js
@@ -520,7 +527,7 @@ ES module wrapper is used for `import` and the CommonJS entry point for
520527 " main" : " ./index.cjs" ,
521528 " exports" : {
522529 " require" : " ./index.cjs" ,
523- " default " : " ./wrapper.mjs"
530+ " import " : " ./wrapper.mjs"
524531 }
525532}
526533```
@@ -605,8 +612,8 @@ CommonJS and ES module entry points directly (requires
605612 " type" : " module" ,
606613 " main" : " ./index.cjs" ,
607614 " exports" : {
608- " require " : " ./index.cjs " ,
609- " default " : " ./index.mjs "
615+ " import " : " ./index.mjs " ,
616+ " require " : " ./index.cjs "
610617 }
611618}
612619```
@@ -1149,7 +1156,7 @@ of these top-level routines unless stated otherwise.
11491156_isMain_ is **true** when resolving the Node.js application entry point.
11501157
11511158_defaultEnv_ is the conditional environment name priority array,
1152- ` [" node" , " default " ]` .
1159+ ` [" node" , " import " ]` .
11531160
11541161<details>
11551162<summary>Resolver algorithm specification</summary>
0 commit comments