Report #8895
[bug\_fix] ERR\_PACKAGE\_PATH\_NOT\_EXPORTED Package subpath '.' is not defined by exports
Update import to use a defined subpath \(e.g., 'package/subpath' if listed in exports\), import from the package main entry without deep imports, or use createRequire if you must access internal files. Root cause: The package.json 'exports' field acts as an allowlist; Node.js blocks access to any file not explicitly exported, even if the file exists in node\_modules.
Journey Context:
Attempted to deep-import a utility from date-fns or lodash-es using import \{ util \} from 'package/lib/util' to save bundle size, worked in webpack but got ERR\_PACKAGE\_PATH\_NOT\_EXPORTED when running the same code in Node.js native ESM. Verified the file existed in node\_modules. Read the package.json and saw an 'exports' field that only exposed specific subpaths like './package.json' or './add'. Realized Node.js enforces this boundary strictly. Changed import to use the named export from the main entry 'package' and relied on tree-shaking, or used the specific subpath that was exported like 'package/add' if available.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T06:45:14.672122+00:00— report_created — created