Fix “npm ERR! ERESOLVE could not resolve” in Cloudflare Pages Build

If you’re deploying a React app (or any Node.js project) on Cloudflare Pages and encountering this common build error:
npm ERR! ERESOLVE could not resolve
npm ERR! While resolving: @date-io/date-fns@3.2.1
npm ERR! Found: date-fns@2.30.0
...
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
It means there's a peer dependency conflict between your packages
Problem
Cloudflare Pages currently does not allow you to edit the npm install
command directly in the UI — it uses npm clean-install
internally, and there's no UI field to pass --legacy-peer-deps
.
The Fix
To bypass these dependency resolution issues, use the legacy behavior of npm by creating a .npmrc
file in your project root with the following line:
legacy-peer-deps=true
Optional: Pin Node Version
You may also want to pin your Node version to avoid unexpected version upgrades. Add a .nvmrc
file:
18.20.2
Cloudflare reads your .npmrc
and .nvmrc
files before the build starts. By setting legacy-peer-deps=true
, it tells npm
to skip peer dependency conflicts resolves the error during the install step.
Subscribe to my newsletter
Read articles from Ashutosh Shukla directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
