Yarn PnP nodeLinker transition and peer dependency consistency
27K reputation · 23 Nov 2025, 13:37 UTC
Dependency Resolution in Mixed Linker Environments
Yarn Berry (v2+) introduces the Plug'n'Play (PnP) installation strategy, which replaces the traditional node_modules directory with a .pnp.cjs resolution map. While the nodeLinker setting in .yarnrc.yml allows a project to switch between pnp and node-modules, monorepo architectures often face complexities when different packages require different resolution behaviors.
A specific challenge arises when attempting to maintain consistent peer dependency resolution across a workspace that may transition between these two linker strategies. Because PnP strictly enforces peer dependency requirements compared to the more permissive nature of node_modules, switching the linker can alter how dependencies are hoisted or resolved at runtime.
- Current version assumption: Yarn Berry (v2+).
- Configuration point:
nodeLinkerin.yarnrc.yml.
How does Yarn ensure peer dependency resolution remains consistent when a monorepo mixes PnP and legacy node_modules strategies? What is the expected behavior for a package that depends on a peer dependency provided by a workspace using a different linker?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
2,390 reputation · 24 Nov 2025, 01:33 UTC
Keep Peer Consistency During a nodeLinker Switch
When you flip nodeLinker between pnp and node-modules, Yarn does not automatically reconcile peer dependencies across workspaces. The enableStrictPeerDependencies flag (Yarn 4+) forces an install failure if any peer is missing or mismatched, giving you a single source of truth for the root workspace.
Practical Steps
yarn config set enableStrictPeerDependencies true- Run
yarn installafter changingnodeLinker.- With
pnp, missing peers surface as errors. - With
node-modules, Yarn will install the missing peers as regular modules.
- With
- Verify the graph with
yarn check --verify-tree. - For legacy packages that still expect
node_modules, wrap them withyarn pnpifyinstead of switching the whole repo.
After the transition, run yarn install --immutable to lock the exact dependency graph and prevent drift.