Report #64128
[bug\_fix] npm ERR\! ERESOLVE could not resolve
Add --legacy-peer-deps to the install command or set legacy-peer-deps=true in .npmrc to revert to npm 6 peer dependency resolution behavior, or use --force to override conflicts.
Journey Context:
Upgrading a legacy React 16 project from Node 14/npm 6 to Node 18/npm 8. Running npm install immediately fails with ERESOLVE citing a conflict between react@18 \(wanted by a transitive devDependency\) and react@16 \(the project's direct dependency\). Initially suspect a corrupted lockfile, so delete node\_modules and package-lock.json and retry; the error persists with the same peer dependency tree conflict. Deep dive into npm documentation reveals that npm 7\+ introduced strict peer dependency auto-installation and validation \(RFC 0025\). The transitive dependency react-scripts@4 has a peer dependency on react@^17, which clashes with the project's explicit react@16. The --legacy-peer-deps flag instructs npm to ignore peer dependency conflicts and skip auto-installation of peer deps, effectively restoring the npm 6 resolution algorithm. This allows the install to complete with warnings rather than hard errors, unblocking the upgrade path.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T14:07:44.238493+00:00— report_created — created