What-If Walkthrough: The Day "exports" Closed the Back Door
This long scenario is hypothetical. "Library K" is an invented date-handling package, and the user counts are assumptions. It follows one change, adding the exports field to package.json, through four decision points, and at each one asks what would have happened if the maintainers had chosen differently.
Background
Library K 5.x has a main entry, but its documentation once suggested importing individual helpers directly to save bundle size:
import addDays from "library-k/lib/addDays.js";
That advice was removed from the README years ago, yet assume a large share of users still do it. Node.js documents that once a package defines exports, only the listed subpaths can be imported; any other path fails with ERR_PACKAGE_PATH_NOT_EXPORTED. The Node.js documentation also notes that introducing exports to an existing package can therefore be a breaking change.
Decision point 1: should the field be added at all?
The maintainers want exports to ship separate ESM and CommonJS builds through conditional exports. That is a sound goal. What if they skip it? Nothing breaks, but the dual-format build stays fragile and deep imports keep pinning internal file layout, so any future refactor of lib/ breaks someone silently. Doing nothing postpones the pain rather than avoiding it.
Decision point 2: minor or major?
Branch A: they publish it as 5.9.0. Users with caret ranges upgrade automatically and every deep import fails at load time. Branch B: they publish 6.0.0. Nobody is upgraded by surprise; users opt in and read the migration notes. Branch A is the one that turns into an incident, so this scenario follows Branch B from here.
Decision point 3: how strict should the map be?
Three shapes were on the table:
| Option | Map | Trade-off |
|---|---|---|
| Root only | ".": {...} | Smallest surface; every deep importer must change code |
| Named subpaths | "./addDays": "./lib/addDays.js" per helper | Clean public paths; long map to maintain |
| Wildcard escape hatch | "./lib/*": "./lib/*" | Keeps old imports alive; freezes internal layout as public API |
The team chose named subpaths plus a temporary wildcard pattern for ./lib/* that they documented as deprecated, with removal planned for 7.0. What if they had gone root-only? The upgrade would have been cleaner on paper but, under the assumption that many users deep-import, the 6.0 adoption rate would likely stall and the 5.x line would need security backports for much longer.
"exports": {
".": { "import": "./esm/index.js", "require": "./cjs/index.cjs" },
"./addDays": { "import": "./esm/addDays.js", "require": "./cjs/addDays.cjs" },
"./lib/*": "./lib/*",
"./package.json": "./package.json"
}
Exporting ./package.json is a small courtesy: some tools read it, and without the entry they cannot.
Decision point 4: how to tell people
The 6.0.0 changelog opened with the exports change, listed every supported subpath, and showed a before-and-after import. A migration page explained how to search a codebase for library-k/lib/. What if the note had been one line saying "added exports field"? Most readers would not connect that phrase to their broken imports, and the issue tracker would fill with duplicates.
What to take from it
- Treat everything that can be imported today as public, whatever the README says.
- Adding
exportsto an existing package belongs in a major release. - Test the packed tarball by importing every documented path from a scratch project.
Related reading: the package.json exports field and building a dual ESM/CJS package.