pnpm Monorepo React 19 Migration: Resolving Type Conflicts Caused by a Hidden Hoisting Layer
Key point
By analyzing pnpm's structure, the dependency type pollution issue that occurred during a React 19 migration in a pnpm monorepo is resolved.
Details
In a pnpm workspace-based monorepo environment, pnpm catalogs was introduced for a phased migration to React 19. The goal was to independently isolate the dependencies of the existing React 18 apps and the new React 19 apps, preventing version fragmentation.
However, during the migration process, a Type Pollution phenomenon occurred where the existing React 18 apps ended up referencing React 19's types. This caused children and ReactNode type inference to go awry, resulting in a flood of TypeScript errors.
The cause of the problem lay in pnpm's unique node_modules structure. pnpm uses a Global Store and Hard Link to improve efficiency, and has a 3-layer structure that blocks phantom dependencies via Symbolic Link.
- Layer 1 (Strict Interface Layer): Each app's
node_modules, where only the packages specified inpackage.jsonare connected via symbolic links, ensuring independence. - Layer 2 (.pnpm Virtual Store): The actual implementation of the dependency graph and the destination that the symbolic links point to.
This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.
Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.