Bye Bye “npm ERR! Conflicting peer dependency”
When working on an npm project, you may encounter a common error message that reads “conflicting peer dependency” while trying to install a package via npm. This error can be quite frustrating and slow down your development process.
In this article, you will understand what a peer dependency is, why this error occurs, and how to fix it.
Before digging into how to address the npm error, let’s focus on some key concepts you need to know.
What is a peer dependency?
In npm, a peer dependency is a package that needs another package to work but does not include it in its own installation. In other words, a peer dependency specifies that a package is compatible with a specific host tool or library, while not requiring it directly.
Peer dependencies are specified in the
package.json file in the
peerDependencies section. This mechanism is particularly useful when it comes to building npm plugins. When using a peer dependency, the npm module is saying, “I only work when plugged in to version x.y.z of a particular host package. So, if you install me, make sure it is alongside a compatible host.”
From version 4 to 6, npm stopped supporting automatic installation of
peerDependencies due to technical issues with the deduplication algorithm. However, since version 7, npm relies on the Arborist algorithm to automatically install
Why does the “conflicting peer dependency” error occur?
This error occurs when there is a conflict between the versions of the peer dependencies required by different packages your projects rely on. For example, if package A requires version 1.0 of a peer dependency, and package B requires version 2.0 of the same dependency, npm will not be able to resolve this conflict. As a result, it will throw that error.