Skip to content

fix(arborist): handle links with cleared targets - #9820

Open
ljepson wants to merge 1 commit into
npm:latestfrom
ljepson:pr/stale-link-matches
Open

fix(arborist): handle links with cleared targets#9820
ljepson wants to merge 1 commit into
npm:latestfrom
ljepson:pr/stale-link-matches

Conversation

@ljepson

@ljepson ljepson commented Jul 29, 2026

Copy link
Copy Markdown

Hit this reifying a pnpm-shaped node_modules, npm died with:
TypeError: Cannot read properties of null (reading 'matches') out of Node.matches()

Reassigning a node's root clears target on every link pointing at it, so you can end up with a link where isLink is true but target is null.

matches() dereferenced it. Guarding both sides makes a targetless link just not match, which is what the caller wanted anyway. Test builds two links to a shared target and reassigns the target's root to clear both. It throws without the fix.

I left the guard inside the existing this.isLink branch rather than restructuring, a plain Node compared against a Link still falls through the same way, so placement and dedupe are untouched.

@ljepson
ljepson requested review from a team as code owners July 29, 2026 16:44
@ljepson
ljepson marked this pull request as draft July 29, 2026 16:52
@ljepson
ljepson force-pushed the pr/stale-link-matches branch 3 times, most recently from 87a13ec to 5d43dc1 Compare July 30, 2026 19:20
@ljepson
ljepson marked this pull request as ready for review July 30, 2026 19:32
@ljepson
ljepson force-pushed the pr/stale-link-matches branch 2 times, most recently from 60b2c44 to 80e1de2 Compare August 17, 2026 22:24
Reassigning a node's root clears `target` on every link pointing at
it, leaving a link with `isLink` true but no target. Comparing such a
link in `matches()` crashed with `TypeError: Cannot read properties
of null (reading 'matches')`.

A link whose target was detached still knows the realpath it pointed
at, so fall back to comparing realpaths. Two such links then give the
same answer they gave before their targets were cleared, instead of
reporting a spurious mismatch.
@ljepson
ljepson force-pushed the pr/stale-link-matches branch from 80e1de2 to 7589245 Compare August 17, 2026 23:06
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.

1 participant