← Back to Pull requests

doc: explain fallback arrays in package exports targets #67393

Closed
unknown closed this pull request without merging on Nov 12, 2026 21:07 UTC
View on GitHub
unknown unknown commented on Nov 10, 2026 20:55 UTC
Author

The "exports" field definition lists string[] as an accepted type, but
packages.md never explains how an array of targets is resolved. This has
led 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:

  • an array can be used anywhere a target is accepted, in both "exports"

  • and "imports", and items are tried in order;
  • an item is skipped only if it is an invalid target or a conditions

  • object with no matching condition;
  • file existence is not checked, so a valid first target that points to a

  • missing file fails instead of falling through to the next item;
  • an empty array means the subpath is not exported, and if every item is

  • invalid the last error is thrown.

    The wording follows PACKAGE_TARGET_RESOLVE in esm.md and
    resolvePackageTarget() in lib/internal/modules/esm/resolve.js.

    Verification

    Tested with a small package in node_modules on Node.js <YOUR VERSION>,
    using both require() and import():

    | exports target | 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.md passes.

    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

    Diff: 247 lines (+185 / -62) across 3 files Reviewer: jsumners-nr Review duration: 2892m
    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
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 38.9% (MEDIUM) · Higher = larger blast radius
    38.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.4% · Safe to merge
    15.4%
    Repository