Repository navigation
doc: explain fallback arrays in package exports targets - #67393
Open
manusingh090 wants to merge 1 commit into
Open
manusingh090 wants to merge 1 commit into
manusingh090 wants to merge 1 commit into
Conversation
The "exports" field type lists `string[]`, but the packages documentation never describes how an array of targets is resolved. Document that items are tried in order, that only invalid targets and unmatched conditions are skipped, and that a missing file does not cause the next item to be tried. Fixes: nodejs#58600 Signed-off-by: Manjeet Singh <024manjeetsingh@gmail.com>
Collaborator
|
Review requested:
|
Contributor
|
Welcome to Node.js, and thank you for your first contribution! Before review, please take a moment to read:
Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal. |
jsumners-nr
approved these changes
Nov 11, 2026
JakobJingleheimer
approved these changes
Nov 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
"exports"field definition listsstring[]as an accepted type, butpackages.mdnever explains how an array of targets is resolved. This hasled people to assume an array falls back to the next file when the first
one does not exist (see the linked issue), which is not what happens.
This adds a "Target fallback arrays" section after "Nested conditions"
that documents:
"exports"and
"imports", and items are tried in order;object with no matching condition;
missing file fails instead of falling through to the next item;
invalid the last error is thrown.
The wording follows
PACKAGE_TARGET_RESOLVEinesm.mdandresolvePackageTarget()inlib/internal/modules/esm/resolve.js.Verification
Tested with a small package in
node_moduleson Node.js ,using both
require()andimport():exportstarget["./nope.js", "./b.js"]["../outside.js", "./b.js"]./b.js[{ "browser": "./nope.js" }, "./b.js"]./b.js[]ERR_PACKAGE_PATH_NOT_EXPORTED["../x.js", "../y.js"]ERR_INVALID_PACKAGE_TARGETnode tools/lint-md/lint-md.mjs doc/api/packages.mdpasses.AI disclosure
I used an AI coding assistant to help read the resolver code and draft the
text. I reviewed the section against the resolver source and ran the tests
above myself.
Fixes: #58600