Originally the exports proposal had a way to specify the main field as well. The following was the equivalent of setting main to './lib/entry.mjs':
{
"exports": {
".": "./lib/entry.mjs"
}
}
We discarded this for two reasons:
- Without dual-mode, having two separate values seemed confusing.
- There were educational and aesthetic concerns with a property key that's just "." without additional context.
But with fallbacks and/or differential serving, we run into a new reason for wanting this second key: Backwards compatibility.
The problem is that if I'm maintaining a package std-x-polyfill and I want to fall back to the native std:x module where it's available, I could express it like this:
{
"main": ["std:x", "./lib/x-polyfill.cjs"]
}
The problem is now: This package cannot be used in anything but the latest version of node. Older versions will not recognize this kind of main field. If we'd support exports[.] as an alternative with higher priority, the problem can be solved (if a bit verbose):
{
"main": "./lib/x-polyfill.cjs",
"exports": {
".": ["std:x", "./lib/x-polyfill.cjs"]
}
}