Skip to content

Add a fallback lookup for esm only modules - #6003

Merged
knolleary merged 1 commit into
mainfrom
fix/5977-esm-import-only-exports
Oct 14, 2026
Merged

knolleary merged 1 commit into
mainfrom
fix/5977-esm-import-only-exports

Conversation

@knolleary

Copy link
Copy Markdown
Member

Resolve 'import' export condition for ESM-only function node modules based on package.json contents.

  • importModule still tries createRequire(moduleDir).resolve(module) first, so nothing changes for packages that already worked.

  • If that fails with ERR_PACKAGE_PATH_NOT_EXPORTED, a new resolveImportExport() reads the package's package.json and works out the file from exports using the import, node and default conditions. It handles:

    • the main export, written as a single string, a conditions object, or a "." entry
    • subpath entries such as "./extra"
    • wildcard patterns such as "./*.js", preferring the most specific match
    • conditions nested inside other conditions, and fallback arrays
  • A file path in exports is only used if it starts with ./ and stays inside the package folder.

  • If the fallback can't find a file, the original Node error is thrown, so the message users see stays the same.

@knolleary
knolleary merged commit 277bf6e into main Oct 14, 2026
3 checks passed
@knolleary
knolleary deleted the fix/5977-esm-import-only-exports branch October 14, 2026 12:44
AndreKR added a commit to AndreKR/imglib that referenced this pull request Nov 26, 2026
It should no longer be necessary since
node-red/node-red#6003.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /data/node_modules/@andrekr/imglib/package.json

1 participant