Peer Dependencies
The --legacy-peer-deps
flag in npm is used to ignore peer dependency conflicts during installation. It essentially tells npm to use the older (pre-npm v7) behavior when resolving dependencies.
What are Peer Dependencies?
peerDependencies
are packages that a module expects the parent project to provide. For example:
{
"peerDependencies": {
"react": "^17.0.0"
}
}
This means: "I need React, but I expect you to already have it installed in your project."
Why does installation fail?
Starting with npm v7, npm enforces strict resolution of peer dependencies. If two packages require incompatible versions of the same peer dependency, the install will fail. In earlier versions (npm v6 and below), it would just warn you instead.
What does --legacy-peer-deps do?
It disables the strict peer dependency enforcement, allowing the install to proceed even if peer dependencies are incompatible:
npm install some-package --legacy-peer-deps
This will skip peer conflict checks and install anyway — like npm v6 used to do.
When should you use it?
- ✅ Use it if you're just trying to get a project up and running quickly.
- ⚠️ Avoid relying on it for production or long-term solutions. It's better to manually resolve dependency conflicts to avoid runtime issues later.