npm ERESOLVE on @types/react - Fix Type Peer Conflicts in CI
A very common ERESOLVE case is not React itself but its type packages: a transitive library pins one @types/react major while your project resolves another, and npm cannot reconcile the two.
What this error means
npm install/npm ci aborts with ERESOLVE naming @types/react (or @types/react-dom), showing one package wanting types for React 18 while your tree has types for 17 or 19. The runtime React version is fine; only the type peers collide.
npm error code ERESOLVE
npm error Could not resolve dependency:
npm error peer @types/react@"^18.0.0" from @some/ui-types@2.0.0
npm error Conflicting peer dependency: @types/react@19.0.2
npm error node_modules/@types/reactCommon causes
Type packages drifted from the React major
A dependency pins @types/react to one major while your project (or another dep) brings in a different major, so npm has two incompatible type peers in one tree.
A stray @types/react in dependencies
Listing @types/react as a hard dependency at a different major than your React/react-dom types causes a conflict every clean install.
How to fix it
Align the type packages to the React major
Pin @types/react and @types/react-dom to the major that matches the React you run, then regenerate the lockfile.
npm install -D @types/react@18 @types/react-dom@18
rm -f package-lock.json && npm installForce one types version with overrides
- Add an
overridesblock pinning@types/reactto one version for the whole tree. - Verify the type-check still passes against that pinned major.
- Regenerate and commit the lockfile so CI installs the same tree.
How to prevent it
- Keep @types/react(-dom) on the same major as react(-dom).
- Use
overridesto pin a single types version across the tree. - Commit the lockfile and install with
npm ci.