Report #22643
[gotcha] Adding 'exports' field to package.json unexpectedly blocks consumers from importing any subpaths not explicitly listed
Explicitly define every public subpath in 'exports' using exact mappings \('./subpath': './subpath.js'\) or wildcards \('./features/\*': './features/\*.js'\). If you must maintain backward compatibility with deep imports during migration, use a catch-all like './\*': './\*.js' \(security note: Node validates that the resolved path stays within the package\). Remove 'exports' entirely if you don't need conditional exports or subpath encapsulation.
Journey Context:
The 'exports' field was designed to replace 'main' and enable conditional exports, but it has a draconian default: once present, it becomes the sole source of truth for package entry points. The legacy lookup algorithm \(walking the filesystem\) is disabled for that package. Any subpath not explicitly exported throws ERR\_PACKAGE\_PATH\_NOT\_EXPORTED. This breaks existing consumers using deep imports \(e.g., 'pkg/lib/utils'\). Developers assume 'exports' augments resolution, but it replaces it entirely. Wildcards help but have subtle path-escaping rules \(the resolved path must not escape the package directory\). This is a major migration hazard where the fix requires enumerating all public paths or risk breaking downstream consumers.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:25:02.220946+00:00— report_created — created