Migrating npm to pnpm 9: `ERR_PNPM_PEER_DEP_ISSUES` and the lockfile mess
We moved one of our front-end repos from npm to pnpm last sprint. I was the one who suggested it, mostly to get our disk usage down, and I spent most of the sprint eating the consequences. The migration itself was quick. The peer dependency errors were not.
## The error that blocked CI
Local install worked. CI did not:
$ pnpm install --frozen-lockfile
ERR_PNPM_PEER_DEP_ISSUES Unmet peer dependencies.
└── react-dom 18.2.0
└── ✕ unmet peer react@^18.2.0: found 17.0.2
A failure was found when resolving peer dependencies, use --no-strict-peer-dependencies to suppress it.
We were on pnpm 9.4.0 and Node 20.11. npm had been quietly installing a second copy of React to satisfy that peer; pnpm refused and told us about it. That strictness is the point of pnpm, but it makes migrations loud.
## What was actually wrong
React 17 and React 18 don't coexist happily. We had react pinned at 17 in the root package.json and react-dom at 18 from a component library that had declared it as a dependency rather than a peer. npm's flat-ish node_modules had hidden this by hoisting one version and nesting the other. pnpm's symlinked store has no such hiding, so the conflict surfaced immediately.
I verified with:
pnpm why react
pnpm why react-dom
That showed exactly two versions in the graph. Good tool, by the way, pnpm why is much easier to read than npm's ls.
## The fix
We aligned the versions properly instead of suppressing the error:
pnpm add react@^18.2.0 react-dom@^18.2.0
pnpm install --frozen-lockfile
Then we removed the stale package-lock.json and committed the new pnpm-lock.yaml. The suppression flag exists, and I used it once to unblock a deploy, but it just defers the problem. If you use it, write down why.
## The config we landed on
pnpm's strict linking broke one of our build tools that expected to import a transitive dependency it never declared. We added a .npmrc:
strict-peer-dependencies=true
auto-install-peers=true
node-linker=hoisted
node-linker=hoisted was the concession. It gives us a node_modules layout closer to npm's, which fixed the build tool, at the cost of some of pnpm's disk savings. Worth it for us. Not for everyone, I know.
## What I'd tell my past self
Do the migration on a branch with a clean pnpm install in CI from day one. Our first few commits used --no-frozen-lockfile, which let the lockfile drift and made the final CI failure confusing. Once we switched to frozen lockfiles the errors became honest.
Disk usage did drop, from about 1.4 GB to 600 MB per workspace. The peer dependency cleanup was the real work.
Two other things came out of this. First, pnpm-lock.yaml does not merge nicely when two branches both add a dependency. We now treat the lockfile as generated and regenerate it on the branch that lands last, rather than trying to hand-resolve the YAML. Second, we added a pnpm.overrides block to pin a transitive package that kept resolving to two versions. That felt like cheating at first, but it's documented and it keeps pnpm why readable. Both decisions are in a comment at the top of our package.json so nobody has to rediscover them. If you've done this with a monorepo and kept strict linking, I'd be curious how you handled undeclared transitive imports.