fix(arborist): avoid crash when peer back-off detaches a node#9770
Open
manzoorwanijk wants to merge 1 commit into
Open
fix(arborist): avoid crash when peer back-off detaches a node#9770manzoorwanijk wants to merge 1 commit into
manzoorwanijk wants to merge 1 commit into
Conversation
manzoorwanijk
marked this pull request as ready for review
July 15, 2026 15:54
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.
Installing a package whose peers form a cycle with an already-installed optional peer could crash with
TypeError: Cannot read properties of null (reading 'explain')instead of resolving or reporting a real conflict.A minimal trigger:
vite@8.1.4declares an optional peer on@vitejs/devtools,@vitejs/devtoolspeers back onvite, so installing vite and then adding devtools crashes.The root cause is in
#loadPeerSet.While resolving a package's peer edge through the parent's edge, the recursive
#nodeFromEdgecall can place a compatible peer that replaces and detaches the current node from the tree mid-iteration.The now-invalid edge then reached
#failPeerConflict, whose#explainPeerConflictcallsnode.resolve(edge.name).explain()on the detached node.resolve()returnsnullfor a node no longer in the tree, so.explain()threw.A detached node has been superseded by a compatible peer, so there is no real conflict to report.
The fix adds a guard that stops processing when the node has been detached, right before
#failPeerConflict, mirroring the existing top-of-loop detachment check.This lets the install complete by keeping the compatible peer that replaced the node (for the reproduction,
@vitejs/devtoolsbacks off to a version that satisfies vite's optional peer range) rather than crashing or raising a spuriousERESOLVE.References
Fixes #5222
Closes #4787