What is a peer dependency in npm?
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · 11.19.0updated 2026-10-20
- tool
- npm
- versions
- npm 7+
- os
- any
A peer dependency is a package that a library needs but expects the project using it to install, so that the library and the project share one copy. Plugins and framework bindings use them: react-dom declares react as a peer, because two copies of React in one app do not work.
See a package's peer dependencies
npm view react-dom@19.0.0 peerDependenciesOutput
{ react: '^19.0.0' }How npm treats them
- npm 7 and later install peer dependencies automatically and fail with
ERESOLVEwhen the range cannot be satisfied. - npm 3 to 6 only printed a warning and left installing the peer to you.
peerDependenciesMetacan mark a peer as optional:{ "some-peer": { "optional": true } }.
In package.json
{
"name": "my-react-widget",
"peerDependencies": {
"react": "^18.0.0 || ^19.0.0"
}
}A wide range like ^18.0.0 || ^19.0.0 lets the plugin work in projects on either major version, which avoids most ERESOLVE conflicts.
Sources
Related pages
errors · npmnpm ERR! code ERESOLVE: unable to resolve dependency treenpm fails with ERESOLVE when a package's peer dependency conflicts with the version you install. Read Found and Could not resolve, then align the versions.flags · npmnpm install --legacy-peer-deps: what it does and when to use it--legacy-peer-deps makes npm skip installing and checking peer dependencies, as npm 6 did, so ERESOLVE conflicts no longer stop the install. Risks and fixes.compare · npmnpm ci vs npm install: differences and when to use eachnpm ci installs exactly what package-lock.json says, deletes node_modules first and never edits the lockfile; npm install resolves ranges and may update it.