npm install fails with ERESOLVE during my Vercel deployment
npm ERR! code ERESOLVEShort answer
ERESOLVE means two packages ask for incompatible peer dependency versions and npm refuses to guess. On Vercel, set the project's Install Command to npm install --legacy-peer-deps, or fix the versions. Also check .npmrc: strict-peer-deps=true turns a warning into this failure.
Fix it fast
1Find out which cause you have
Reproduce the install in a clean checkout. The error block names the package that wants one version and the package that has another.
rm -rf node_modules npm install2Match what you see, then jump to its fix
- 1
The error block lists a Found version and a peer requirement that does not include itTwo packages need incompatible peer dependenciesFix - 2
The same project installs with warnings on one machine and fails on anotherstrict-peer-deps is on in .npmrcFix - 3
You added a flag locally, and the Vercel log still shows a plain npm installThe project's Install Command override is not what you thinkFix
- 1
What does the error look like?
npm ERR! code ERESOLVEnpm ERR! ERESOLVE unable to resolve dependency tree
Cause 1 of 3
Two packages need incompatible peer dependencies
1Check
Read the Found and peer lines in the error. The package on the peer line is the one whose supported range does not include the version you installed.
npm ls react2Fix
Upgrade or replace the package whose peer range is too old. If you cannot, tell Vercel to install the way npm 6 did, with peer dependencies ignored. Set installCommand in vercel.json.
{
"installCommand": "npm install --legacy-peer-deps"
}3Verify
Redeploy. The Install step in the build log should finish without ERESOLVE.
vercel deployConfirmed by docs.npmjs.com
Cause 2 of 3
strict-peer-deps is on in .npmrc
1Check
With strict-peer-deps set to true, npm fails on any conflicting peer dependency instead of picking the nearest version and warning.
cat .npmrc
npm config get strict-peer-deps2Fix
Remove the strict-peer-deps line from the project's .npmrc, or set it to false.
# .npmrc
strict-peer-deps=false3Verify
Run a clean install again.
rm -rf node_modules
npm installConfirmed by docs.npmjs.com
Cause 3 of 3
The project's Install Command override is not what you think
1Check
Vercel can override the install command from the dashboard, or per deployment with installCommand in vercel.json. A flag typed only in your terminal never reaches the build.
cat vercel.json2Fix
Put the command you want in vercel.json, or in Settings, Build and Deployment, Install Command.
{
"installCommand": "npm install --legacy-peer-deps"
}3Verify
Open the new deployment's build log and read the install line.
# Dashboard: open the new deployment and read the install line in its build logsConfirmed by vercel.com
How do I stop it coming back?
- Commit package-lock.json so Vercel installs the tree you resolved locally.
- Prefer upgrading the package whose peer range is out of date over ignoring peers.
- Keep the Node.js and npm versions on your machine close to the ones in Vercel's project settings.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
npm install refuses with ERESOLVE and a peer dependency conflict
npm error ERESOLVE unable to resolve dependency tree
ERESOLVE means two packages in your tree ask for incompatible versions of a shared peer dependency, and npm 7 or newer refuses to guess.
3 causes, each with a fixWeb apps
tsconfig rejects allowImportingTsExtensions
An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly
allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.
2 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fix