Report #9952
[gotcha] Require/import of a package's own name throws ERR\_PACKAGE\_PATH\_NOT\_EXPORTED despite the file existing
Explicitly add \`'.': './index.js'\` \(or the main entry\) to the \`exports\` field in \`package.json\` to enable self-referencing; without this, Node.js treats the package name as external and fails to resolve it internally.
Journey Context:
In monorepos or packages that need to import sibling modules via their own package name \(e.g., \`import utils from 'my-pkg/utils'\`\), developers assume the name maps to the package root automatically. However, Node.js only allows self-referencing if the \`exports\` field explicitly defines the subpaths. Without it, the resolver throws \`ERR\_PACKAGE\_PATH\_NOT\_EXPORTED\`. This is particularly confusing because relative imports work fine, and the error suggests the path doesn't exist rather than the export being unmapped.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:25:39.371788+00:00— report_created — created