Commit 74eff59
authored
fix(arborist): avoid crash when peer back-off detaches a node (#9770)
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.4` declares an optional peer on
`@vitejs/devtools`, `@vitejs/devtools` peers back on `vite`, 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 `#nodeFromEdge` call 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
`#explainPeerConflict` calls `node.resolve(edge.name).explain()` on the
detached node.
`resolve()` returns `null` for 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/devtools` backs off to
a version that satisfies vite's optional peer range) rather than
crashing or raising a spurious `ERESOLVE`.
## References
Fixes #5222
Closes #47871 parent 882d0b2 commit 74eff59
2 files changed
Lines changed: 53 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1639 | 1639 | | |
1640 | 1640 | | |
1641 | 1641 | | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
1642 | 1648 | | |
1643 | 1649 | | |
1644 | 1650 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4838 | 4838 | | |
4839 | 4839 | | |
4840 | 4840 | | |
| 4841 | + | |
| 4842 | + | |
| 4843 | + | |
| 4844 | + | |
| 4845 | + | |
| 4846 | + | |
| 4847 | + | |
| 4848 | + | |
| 4849 | + | |
| 4850 | + | |
| 4851 | + | |
| 4852 | + | |
| 4853 | + | |
| 4854 | + | |
| 4855 | + | |
| 4856 | + | |
| 4857 | + | |
| 4858 | + | |
| 4859 | + | |
| 4860 | + | |
| 4861 | + | |
| 4862 | + | |
| 4863 | + | |
| 4864 | + | |
| 4865 | + | |
| 4866 | + | |
| 4867 | + | |
| 4868 | + | |
| 4869 | + | |
| 4870 | + | |
| 4871 | + | |
| 4872 | + | |
| 4873 | + | |
| 4874 | + | |
| 4875 | + | |
| 4876 | + | |
| 4877 | + | |
| 4878 | + | |
| 4879 | + | |
| 4880 | + | |
| 4881 | + | |
| 4882 | + | |
| 4883 | + | |
| 4884 | + | |
| 4885 | + | |
| 4886 | + | |
| 4887 | + | |
4841 | 4888 | | |
4842 | 4889 | | |
4843 | 4890 | | |
| |||
0 commit comments