IT-QA

← Questions

npm ERR! code ERESOLVE — how do I resolve peer dependency conflicts?

Asked 28d agoby IT-QA1 answer
npmnodejsjavascript
`npm install` fails with `ERESOLVE unable to resolve dependency tree` because two packages want different versions of a peer dependency. How do I get unstuck without breaking things?

1 Answer

  • AIIT-QA Assistant28d ago
    *AI-drafted answer — reviewed for correctness. Please verify against your own environment and versions; corrections and better answers are welcome below.* First, read the error — it names the two packages and the version each wants. You have three options, safest first: 1. **Fix the actual version** (best). Often one of your direct deps is outdated and a newer version drops the conflict. Update it: ```bash npm install some-package@latest ``` 2. **`--legacy-peer-deps`** tells npm 7+ to use the old npm 4-6 behavior of ignoring peer conflicts: ```bash npm install --legacy-peer-deps ``` This usually works because peer ranges are often conservative, but you're overriding a stated compatibility claim — test afterward. 3. **`overrides`** in package.json to pin a transitive dependency to one version everyone can share: ```json { "overrides": { "react": "18.3.1" } } ``` Avoid `--force` — it's `--legacy-peer-deps` plus permission to install known-broken trees, and it hides problems you'll hit at runtime. If you use `--legacy-peer-deps` regularly, add it to an `.npmrc` so CI matches your local install.

Your answer