npm ERESOLVE peer dependency error on deploy
THE SHORT ANSWER
ERESOLVE means a package's peerDependencies range doesn't accept the version your project already uses, and npm 7 and later refuse to build that tree. It often passes locally because your package-lock.json was made with --legacy-peer-deps, your ~/.npmrc sets legacy-peer-deps=true, or your local npm is older, while the build server runs a clean npm ci without any of that. Fix it by upgrading the package to a version whose peer range fits, by forcing the version with overrides in package.json, or, as a last resort, by committing legacy-peer-deps=true in a project .npmrc so every install, local and on deploy, resolves the same way.
How do I read the ERESOLVE error?
A typical failure looks like this (package names are examples):
npm error code ERESOLVE npm error ERESOLVE unable to resolve dependency tree npm error npm error While resolving: [email protected] npm error Found: [email protected] npm error node_modules/react npm error react@"^19.2.0" from the root project npm error npm error Could not resolve dependency: npm error peer react@"^17.0.0 || ^18.0.0" from [email protected] npm error node_modules/some-chart-lib npm error some-chart-lib@"^3.1.0" from the root project npm error npm error Fix the upstream dependency conflict, or retry this command with --force or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution.
Older npm versions print npm ERR! instead of npm error. Read it in three parts:
Found:is what your project already has:[email protected], required by your ownpackage.json.Could not resolve dependency:is the package that disagrees.some-chart-libdeclaresreactas a peer dependency and only accepts 17 or 18.Conflicting peer dependency:, when present, names the version npm would have needed to install to satisfy that peer.
npm also writes the full explanation to eresolve-report.txt in its cache folder. A variant, ERESOLVE could not resolve, is the same kind of conflict raised at a different step of building the tree.
Why does it fail on deploy but not on my machine?
npm's package.json docs: “In npm versions 3 through 6, peerDependencies were not automatically installed, and would raise a warning if an invalid version of the peer dependency was found in the tree. As of npm v7, peerDependencies are installed by default.” A conflicting peer that used to be a warning is now an error. If you never see it locally, something on your machine is different from the build server:
- The lockfile was made with --legacy-peer-deps. Someone ran
npm install --legacy-peer-depsonce, it worked, and the lockfile was committed. The build server runsnpm ciwithout the flag. npm's docs onnpm ci: if the lockfile was created with flags like--legacy-peer-deps, “you must provide the same flags to npm ci or you are likely to encounter errors.” - Your user .npmrc sets it. A
legacy-peer-deps=trueline in~/.npmrcapplies to every project on your machine and to none on the server. Runnpm config get legacy-peer-depsto check. - A different npm version. Compare
npm -vlocally with the version in the build log. npm 6 only warned about peer conflicts; 7 and later fail. - No lockfile, or one out of date. Without a committed
package-lock.json, the server resolves every range again and can pick a newer release than the one you have, with a different peer range.
Fix 1: make the versions agree
The real fix is a set of versions that fit. Check whether a newer release of the package widened its peer range:
npm view some-chart-lib peerDependencies npm view some-chart-lib@latest peerDependencies
If the latest version accepts your React, upgrade to it. If no version does yet, either wait, switch packages, or move your own dependency to a version inside the range (here, React 18). Then run a plain npm install with no flags, commit the new package-lock.json, and the deploy resolves the same tree.
npm explain react (or npm ls react) shows every package that depends on a given one, which helps when the conflict sits several levels down.
Fix 2: force one version with overrides
When you know the package works with your version and its peer range is just out of date, tell npm to use your version anyway. overrides in the root package.json replaces a version anywhere in the tree, and can be scoped to one parent package:
{
"dependencies": {
"react": "^19.2.0",
"some-chart-lib": "^3.1.0"
},
"overrides": {
"some-chart-lib": {
"react": "$react"
}
}
}$react means “the spec of my direct react dependency”. npm's docs recommend this reference form because you can't override a package you depend on directly with a different spec: that throws EOVERRIDE. Overrides only work in the root package.json, not in dependencies or workspaces.
Unlike --legacy-peer-deps, this is narrow: one package, one peer, written down in package.json where the next person can see it. Every other peer check still runs. Test the feature that uses the package, since its authors haven't promised it works.
Fix 3: legacy-peer-deps in .npmrc
legacy-peer-deps makes npm ignore peerDependencies completely, “as in npm versions 3 through 6”. npm's docs add that its use “is not recommended, as it will not enforce the peerDependencies contract that meta-dependencies may rely on.” It turns off every peer check, not only the one that failed.
If you use it anyway, don't pass it as a flag on your machine only. Commit it, so local installs, npm ci and the build server all build the same tree. npm's own suggestion:
npm config set legacy-peer-deps=true --location=project git add .npmrc package-lock.json
That writes legacy-peer-deps=true to an .npmrc next to package.json. Delete node_modules and run npm install once so the lockfile matches the setting. If you can't add files to the repo, an environment variable does the same thing: npm reads any variable starting with npm_config_ as config, so npm_config_legacy_peer_deps=true works during the build.
Avoid --force for this. It does let conflicting peers into the root project, but it also removes a list of unrelated protections, such as engines checks, and the docs say that without a clear idea of what you want, “it is strongly recommended that you do not use this option!”
npm ci vs npm install on a build server
Build servers usually run npm ci when a lockfile exists. npm's docs list how it differs from npm install:
- The project must have a
package-lock.jsonornpm-shrinkwrap.json. - If the lockfile doesn't match
package.json, it exits with an error instead of updating it. - It removes any existing
node_modulesfirst. - It never writes to
package.jsonor the lockfile.
npm ci still works out the dependency tree before installing, so a peer conflict fails it with the same ERESOLVE. An out-of-sync lockfile gives a different error, which starts “npm ci can only install packages when your package.json and package-lock.json are in sync”. The fix for that one is running npm install locally and committing the lockfile.
Don't switch the build to npm install to dodge ERESOLVE. It hits the same check, and npm ci is what guarantees the server installs what you tested.
What happens on EthioDeploy?
The build picks the install command from your lockfile: npm ci when package-lock.json is committed, npm install when it isn't (pnpm, Yarn and Bun lockfiles get their own frozen installs). Node 22 is the default, which ships with npm 10, unless engines.node in package.json asks for another version.
The ways to apply the fixes above:
- Commit the updated
package.jsonandpackage-lock.json(fixes 1 and 2) and push. - Commit an
.npmrcwithlegacy-peer-deps=truenext topackage.json. The whole repo is in the build, so npm reads it. - Or add
npm_config_legacy_peer_deps=trueas an environment variable. Env vars are available during the build. - Or set the Install Command in Settings → Build, for example to
npm ci --legacy-peer-deps.
If the project builds from your Dockerfile, the Install Command is ignored and your Dockerfile's RUN npm ci line is what runs, so put the .npmrc in the build context before that line. The deploy's build log shows the full ERESOLVE text. For a build that gets further and then dies, see JavaScript heap out of memory during next build.
Questions
A package lists a peer dependency range that doesn't include the version your project uses, and npm 7 and later won't install a tree that breaks a peer range. The Found and Could not resolve dependency lines name the two sides.
It works, but npm's docs call it not recommended: it ignores every peerDependencies range, not just the one that failed. Prefer upgrading the package or a scoped override, and if you do use it, commit it in .npmrc so every install matches.
--legacy-peer-deps ignores peer dependencies while building the tree. --force allows conflicting peers in the root project but also removes other protections, like engines checks, and npm's docs strongly recommend against it unless you know exactly why you need it.
Usually the lockfile was created with --legacy-peer-deps or another tree-shaping flag, and npm ci runs without it. npm's docs say npm ci needs the same flags; committing them in .npmrc does that. An out-of-sync lockfile is a separate error that npm install fixes.
No. It's an npm config setting, so it goes in a project .npmrc file or an npm_config_legacy_peer_deps environment variable. package.json has overrides, which is the narrower alternative.
Sources
Checked on November 15, 2026:
Push a repo. Get a URL.
Start freeJoin the EthioDeploy Telegram
Release notes as they ship, plus deploy help from the team and other developers.