doc: explain fallback arrays in package exports targets #67393
All Vouch review confidence checks passed
Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 247 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.330
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #67393"
general
weight: 0.35
jsumners-nr
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 <YOUR VERSION>,using both
require()andimport():|
exportstarget | Result || ----------------------------------------- | ------------------------------- |
|
["./nope.js", "./b.js"]| module not found ||
["../outside.js", "./b.js"]| loads./b.js||
[{ "browser": "./nope.js" }, "./b.js"]| loads./b.js||
[]|ERR_PACKAGE_PATH_NOT_EXPORTED||
["../x.js", "../y.js"]|ERR_INVALID_PACKAGE_TARGET|node 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: https://github.com/nodejs/node/issues/58600