ERR_PACKAGE_PATH_NOT_EXPORTED
Node.jsERRORCommonModule SystemHIGH confidence

A package path is not exported from a package.

Production Risk

Low. This is a startup error that prevents the application from running, so it is almost always caught during development.

What this means

This error occurs when you try to import a file from a package that is not explicitly exposed through the `exports` field in its `package.json`. The `exports` field is a security and encapsulation feature that prevents users from depending on a package's internal files. You can only import what the package author has made public.

Why it happens
  1. 1Attempting to `import` or `require` an internal utility file from a dependency (e.g., `require('some-package/lib/internal.js')`).
  2. 2The package author has not yet added the desired file to their `exports` map.
  3. 3A typo in the subpath you are trying to import.
How to reproduce

This error happens when resolving an import path for a package that has an `exports` field in its `package.json`, and the requested path does not match any of the defined exports.

trigger — this will error
trigger — this will error
// Assuming 'chalk' package.json has an 'exports' field
// that does not expose 'source/index.js'.
try {
  const chalk = require('chalk/source/index.js');
} catch (err) {
  console.error(err.code);
}

expected output

ERR_PACKAGE_PATH_NOT_EXPORTED

Fix 1

Use the Public Export Path

WHEN The package provides a public API for the functionality you need.

Use the Public Export Path
// Import from the main entry point or a documented public subpath.
const chalk = require('chalk');

Why this works

Consult the package's documentation to find the correct, public way to import the functionality you need. Do not rely on the internal file structure of a dependency.

Fix 2

Request an Export from the Author

WHEN The functionality you need is not exported but seems useful.

Why this works

Open an issue on the package's GitHub repository and request that the author formally export the module you wish to use. This makes the API contract explicit.

Code examples
Triggerjs
// Assuming 'chalk' package.json has an 'exports' field
// that does not expose 'source/index.js'.
try {
  const chalk = require('chalk/source/index.js');
} catch (err) {
  console.error(err.code);  // this triggers ERR_PACKAGE_PATH_NOT_EXPORTED
Handle in try/catchjs
try {
  // operation that may throw ERR_PACKAGE_PATH_NOT_EXPORTED
  riskyOperation()
} catch (err) {
  if (err.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
    console.error('ERR_PACKAGE_PATH_NOT_EXPORTED:', err.message)
  } else {
    throw err
  }
}
Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_package_path_not_exported(...args) {
  // validate args here
  return performOperation(...args)
}
What not to do

Same error in other languages
Sources
Official documentation ↗

https://github.com/nodejs/node/blob/main/lib/internal/modules/esm/resolve.js

More information

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Node.js errors