modules-packagingAnswer last reviewed July 2026

Peer dependencies and hoisting, specifically in a monorepo. How do those actually behave once things get big?

Good answers explain hoisting and peers as mechanisms with real failure modes, phantom deps and duplicate React, grounded in how resolution actually works

What an AI-prepared candidate might say

A peer dependency is the package saying, the host project supplies this, I just work alongside it. The classic case is a React component library, it has to use the app's React instead of shipping its own copy. And modern npm installs missing peers automatically, I think, and errors when the versions conflict. Hoisting is the package manager lifting shared dependencies up to the root node_modules so packages share one copy, and when versions conflict the extra copies stay nested down in the tree. Workspaces link your local packages into the root so they resolve like published ones. The problems that come up are basically two. Hoisting can't reconcile some versions, so you get duplicates, and two Reacts break hooks. And phantom dependencies, where your code imports a package it never declared but hoisting happened to place it at the root anyway.

Senior
Locked

Trace workspace links, peer ranges, and root placement to explain how one library can resolve beside two React installations.

Unlock the depth
Staff
Locked

The invalid-hook-call postmortem walked end to end, CI guards that catch phantoms and duplicates before merge, and the hoisted-versus-strict layout call argued with real costs.

Unlock the depth
Follow-up chain
Peer dependencies and hoisting, specifically in a monorepo. How do those actually behave once things get big? | NodeBook