ERR_PACKAGE_PATH_NOT_EXPORTED node module_error ai_generated true

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './X' is not defined by exports

ID: node/err-package-json-invalid

Also available as: JSON · Markdown
88%Fix Rate
90%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
20 active

Root Cause

Package exports field doesn't expose this subpath. Library changed its exports in a new version.

generic

Workarounds

  1. 92% success Check library changelog for the new import path after the update
    Check library changelog for the new import path after the update

    Sources: https://nodejs.org/api/packages.html#exports

  2. 85% success Pin to the previous version that exposed this subpath
    npm install library@previous-version
    # Or in package.json: "library": "2.x" (pin to major version)

    Sources: https://docs.npmjs.com/cli/v10/commands/npm-install

  3. 90% success Use the library's public API instead of deep imports
    // Old: import X from 'lib/internal/x'
    // New: import { X } from 'lib'

    Sources: https://nodejs.org/api/packages.html#exports

Dead Ends

Common approaches that don't work:

  1. Patch package.json exports field in node_modules 85% fail

    Changes will be lost on next npm install

  2. Use require() to bypass exports restriction 60% fail

    Only works for CJS packages and may break in future

Error Chain

Frequently confused with: