npm ERR! ERESOLVE unable to resolve dependency tree on npm 10.8.2
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: dashboard@2.4.0
npm error Found: react@18.3.1
npm error node_modules/react
npm error react@"^18.3.1" from the root project
npm error
npm error Could not resolve dependency:
npm error peer react@"^17.0.2" from react-datepicker@4.25.0
npm error node_modules/react-datepicker
npm error react-datepicker@"^4.25.0" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
...
That came out of npm install on a project I inherited. Node 20.11.1, npm 10.8.2, a React 18 dashboard that had been installing fine for someone else on npm 8.
## What the error is really saying
Since npm 7, peer dependencies are installed automatically and enforced. react-datepicker@4.25.0 declares peerDependencies: { "react": "^17.0.2" }. The project wants React 18.3.1. npm 10 refuses to guess which one you meant, so it stops. It isn't saying the package literally can't run on React 18, it's saying the package author never promised it would.
One thing that's easy to miss: npm view react-datepicker@7.5.0 peerDependencies queries the registry, not your lockfile. If you're behind a proxy with stale metadata, the output can mislead you. We started passing --registry=https://registry.npmjs.org explicitly in our Docker builds because the internal mirror was about a week behind and kept serving old peer ranges.
That distinction matters, because the two obvious fixes are both bad habits:
npm install --legacy-peer-deps # ignores the whole tree, not just this one peer
npm install --force # installs anyway and hides future conflicts
I've used both. They work right up until the next update, and then you get a different, worse failure.
## How I found the right version
First, confirm the shape of the tree:
$ npm ls react react-datepicker
dashboard@2.4.0 /home/dana/src/dashboard
├── react@18.3.1
└── react-datepicker@4.25.0 invalid: "18.3.1" from the root project
Then check which versions actually support React 18:
$ npm view react-datepicker@7.5.0 peerDependencies
{ react: '^16.9.0 || ^17 || ^18' }
react-datepicker 7.x added React 18 support. Upgrading meant a small API change, selected still works, the CSS import path is still react-datepicker/dist/react-datepicker.css, but dateFormat behaviour around locale changed slightly and I had to adjust two tests.
npm install react-datepicker@7.5.0
Then I pinned it in package.json so nobody's older npm would silently pull 4.x again:
{
"dependencies": {
"react": "18.3.1",
"react-datepicker": "7.5.0"
}
}
## The one that was actually a different problem
A week later the same ERESOLVE shape came back, this time for eslint-plugin-react-hooks wanting an older ESLint. That one wasn't solved by upgrading, the plugin version in the lockfile was just stale. Deleting package-lock.json and reinstalling fixed it, which felt wrong but is sometimes right.
I keep a note in the repo README now: don't reach for --legacy-peer-deps until you've run npm view <pkg>@<version> peerDependencies at least once. Half of these conflicts are just a package that's three major versions behind.