Skip to content

fix(arborist): don't fetch packuments for uninstallable optional peer deps - #9877

Open
danielroe wants to merge 2 commits into
npm:latestfrom
danielroe:fix/opt-peer-deps
Open

fix(arborist): don't fetch packuments for uninstallable optional peer deps#9877
danielroe wants to merge 2 commits into
npm:latestfrom
danielroe:fix/opt-peer-deps

Conversation

@danielroe

@danielroe danielroe commented Aug 14, 2026

Copy link
Copy Markdown

this is a PR aimed to skip fetching packuments for optional peers that won't be installed. this can be extremely costly.

for example, with an empty cache, npm install vite into an empty project installs 10 packages but fetches full packuments for playwright (16.6MB), @types/node (11MB), webdriverio, jsdom, sass, less, terser, and (via vite's optional peer on vitest) all of vitest's optional peers too:

before after
registry requests 86 54
cached registry data ~121MB ~72MB

loadPeerSet resolves unmet optional peer edges into the virtual root, even though they won't be used and in fact be pruned later on

the fix is very simple; we just skip peerOptional edges if they have no current resolution and no parent edge. if something else ends up installing the package, the edge is still validated at placement time.

having said all of that, I'm a relative newcomer to the npm cli, so do let me know if there's a reason for this fetching that I'm missing 🙏

Note

the nest when peerOptional conflicts snapshot did change shape.

imo it was a bug before - the unmet optional peer was eagerly placed and 'won' the top-level slot, forcing the required peer chain to nest, but now the required chain wins and the optional subtree nests instead.

both before/after were valid trees (two copies of the conflicted peer, all edges valid, etc). I've added assertions for this, but it's worth noting that installs with conflicting optional peers can produce a differently shaped node_modules than before.

(ht to @pi0, who spotted this)

References

Fixes #9876

@danielroe
danielroe requested review from a team as code owners August 14, 2026 16:12
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.

[BUG] arborist fetches packuments for optional peer deps that are never installed

1 participant