Skip to content
Latchkey

Node "ERR_INVALID_PACKAGE_TARGET" in package exports in CI

Node rejected a target in the exports (or imports) map. Targets must be relative paths beginning with ./, must stay inside the package, and must not be bare or absolute paths.

What this error means

Resolving a package fails with "Error [ERR_INVALID_PACKAGE_TARGET]: Invalid \"exports\" target ... for './X' defined in the package config".

node
node:internal/modules/esm/resolve:... Error [ERR_INVALID_PACKAGE_TARGET]:
Invalid "exports" target "dist/index.js" defined for './' in the package config
/app/node_modules/my-lib/package.json

Common causes

A target missing the leading ./

Export targets must start with ./ (for example ./dist/index.js); a bare dist/index.js is invalid.

A target that escapes the package

Paths that point outside the package directory (with ../) or to an absolute location are rejected.

How to fix it

Use valid relative targets

Every exports target must be a ./-prefixed path inside the package.

package.json
{
  "exports": {
    ".": "./dist/index.js",
    "./utils": "./dist/utils/index.js"
  }
}

Validate the exports map before publishing

Tools that lint package entry points catch invalid targets and missing conditions before they reach a consumer.

Terminal
npx publint

How to prevent it

  • Prefix every exports/imports target with ./.
  • Keep all targets inside the package directory.
  • Lint package entry points with a tool like publint before release.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →