Node.js ERR_PACKAGE_PATH_NOT_EXPORTED: subpath fix
ERR_PACKAGE_PATH_NOT_EXPORTED means the package exports map never declared the path you imported. Use a declared subpath, the root entry, or fix the map.

Introduction & Quick Summary
Importing a path a package never published fails before any of your code runs:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/utils' is not
defined by "exports" in /app/node_modules/some-pkg/package.json
imported from /app/src/index.jsThe message is literal. some-pkg/package.json contains an exports field, and that field does not list ./lib/utils. Node.js no longer falls back to the file path when exports exists, so a deep import that worked before the package adopted exports now fails. The same happens with require when the map only exposes an import condition, and with TypeScript when the map does not expose types.
The three honest fixes:
- Use a published subpath. Read the map and import a path it declares, such as
some-pkg/utils. - Import the root. Most packages re-export the useful surface from the main entry.
- Publish the subpath if the package is yours, by adding the path to
exportswith the right conditions.
Editing node_modules, deep-requiring with a relative path into the package directory, or monkey-patching the resolver all work until the next install, which is why they are not fixes.
Core Mechanics, Signatures & Reproducible Setup
When package.json has an exports field, it becomes the complete list of entry points. main is ignored for resolution in that case, and any subpath not matched by a key is rejected. Keys are either exact ("./utils") or patterns ("./features/*"), and each value is a set of conditions Node.js evaluates in the order they appear.
{
"name": "some-pkg",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"./utils": {
"types": "./dist/utils.d.ts",
"import": "./dist/utils.js"
},
"./features/*": "./dist/features/*.js"
}
}Reproduce with a small script so the resolution failure is isolated from the framework you are debugging:
node -e "console.log(require.resolve('some-pkg/lib/utils'))" # CJS
node --input-type=module -e "import('some-pkg/lib/utils').catch(e => console.log(e.code, e.message))"The same package can produce three different messages, and each points at a different part of the map:
| Message | Meaning | First check |
|---|---|---|
Package subpath './x' is not defined by "exports" | key absent from the map | the exports keys |
No "exports" main defined in ... | no "." entry | the map's root key |
No known conditions for "./x" specifier | key exists, condition does not | import versus require |
Cannot find module | no exports, wrong path on disk | install state and main |
Key Comparison Table
| Fix | Works next install | Effort | Correct when |
|---|---|---|---|
| Import a declared subpath | yes | minutes | the package exports an equivalent |
| Import the root entry | yes | minutes | the root re-exports the symbol |
Add the subpath to exports | yes | one commit | you maintain the package |
patch-package the dependency | until the version changes | high | temporary unblock with a fork planned |
Relative path into node_modules | no | low | never in application code |
| Bundler alias to the file | fragile | medium | build-time only, documented |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
1. Read the exports map before guessing
Print the field instead of searching documentation that may describe an older version.
node -e "const p=require('./node_modules/some-pkg/package.json'); console.log(JSON.stringify(p.exports,null,2))"
# or, from a script inside the project
node -e "console.log(require('some-pkg/package.json').exports)"If the second command itself fails with ERR_PACKAGE_PATH_NOT_EXPORTED, the map does not expose ./package.json. Read the file directly from node_modules in that case, or check the published files list.
2. require against an import-only package
A CommonJS file requiring a package that only defines import gets the same family of error, because the require condition is absent.
// index.cjs
const pkg = require("esm-only-pkg"); // no "require" condition in exportsTwo legitimate options: load it dynamically from CJS with await import("esm-only-pkg"), or keep the consumer ESM ("type": "module"). Adding a bundler that resolves the import condition also works, but only if the code is actually bundled for a runtime that supports ESM.
3. TypeScript cannot see the types for a declared subpath
moduleResolution: "bundler" or "node16" reads the exports map for types too. A subpath without a types condition resolves at runtime and fails type-checking with TS2307.
{
"compilerOptions": {
"module": "nodenext",
"moduleResolution": "nodenext"
}
}With these settings the compiler follows the same rules as Node, so an error appears at the import rather than at runtime. If the package ships no types at all, install @types/... or declare a module shim with the exact subpath.
4. Workspaces, symlinks, and duplicated installs
In a monorepo, some-pkg may resolve to a workspace symlink whose package.json is the source, not the built output. The exports map then points at dist files that do not exist until the package is built.
ls -l node_modules/some-pkg # symlink into packages/
npm ls some-pkg # duplicated copies?If the map points at build output, build the workspace package before the app, or add a development condition such as "development": "./src/index.ts" that your tooling selects.
5. Wildcard subpaths
A pattern key covers every path under a prefix, which is why one package accepts some-pkg/features/a and another rejects it.
{ "exports": { "./features/*": "./dist/features/*.js" } }The * captures the rest of the specifier, including slashes. A package that only declares "./features/*.js" expects callers to include the extension, which surprises everyone; check the exact pattern before changing the import.
6. You maintain the package
If the missing subpath should be public, add it to the map rather than telling consumers to deep-import. Publish types alongside the runtime file, and keep conditions ordered so types comes before import and require.
{
"exports": {
".": { "types": "./dist/index.d.ts", "import": "./dist/index.js", "require": "./dist/index.cjs" },
"./utils": { "types": "./dist/utils.d.ts", "import": "./dist/utils.js", "require": "./dist/utils.cjs" }
}
}Also add the file to files in package.json. A map entry pointing at an unshipped file produces Cannot find module after install, which is a slower failure to diagnose.
Common Compilation/Runtime Mistakes & Version Gotchas
- Assuming
mainstill wins. Onceexportsexists,mainis only relevant to legacy resolvers. Many older tools still read it, so inconsistent behaviour between the bundler and Node is expected. - Testing with a bundler only. Vite and webpack are more permissive than Node; a build that succeeds can still crash in a plain Node script or a serverless runtime.
- Jest resolution. Jest uses its own resolver and older versions ignored
exports. Upgrading Jest changes which paths resolve and can surface errors that were always there. - Copying files into
node_modules. Any install rewrites the directory. Use a patch file if the change must survive, and open the upstream issue. - Condition order. Conditions are matched in the order written. Putting
requirebeforeimportis valid but changes which file a dual-mode consumer receives.
| Symptom | Cause | Fix |
|---|---|---|
| works in webpack, fails in Node | resolver laxity | use a declared subpath |
| fails after dependency upgrade | exports added | read the new map |
| fails only in tests | Jest resolver | align Jest config or upgrade |
| fails only in production image | missing built dist | build the workspace package |
Package metadata is easier to read as formatted JSON, so paste the package.json into the JSON formatter when comparing two versions, and use the text diff tool to see exactly which export key a lockfile bump removed.
The rules are specified in the Node.js documentation for package entry points and the error itself is listed under Node.js errors. Both describe conditions and patterns more precisely than any summary, and they are short.
Official references
primary documentationThe Node.js documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Node.js work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Node.js guides
All Node.js guidesNode.js: ERR_DLOPEN_FAILED invalid ELF header
Invalid ELF header means a native addon was built for another OS or architecture. Rebuild it inside the target image instead of copying node_modules.
Node.js ERR_INVALID_ARG_TYPE: the argument must be of type
ERR_INVALID_ARG_TYPE is Node's validator naming a wrong argument. Read the quoted argument, validate at the boundary and default env values.
ERR_MODULE_NOT_FOUND: Cannot find module imported from an ESM file
ESM resolves specifiers literally: extensions are required, directories do not resolve to index files, and exports maps block deep imports.
Node.js 26 upgrade: rmdir, native addons and removed flags
Three breaks stop a deploy: rmdir with recursive throws, the transform-types flag is gone, and the module ABI moved to 147.
More in Node.js
All Node.js guidesThe guides filed next to this one in Node.js, in library order.