npm: What are peer dependencies in a Node module?

Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026

The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.


In some package.json files, you might see a few lines like this:

{
  //...
  "peerDependencies": {
    "libraryName": "1.x"
  }
}

You might have already seen dependencies and devDependencies, but not peerDependencies.

dependencies are the packages your project depends on.

devDependencies are the packages that are needed during the development phase. Say a testing framework like Jest or other utilities like Babel or ESLint.

In both cases, when you install a package, its dependencies and devDependencies are automatically installed by npm.

peerDependencies are different. They are not automatically installed.

When a dependency is listed in a package as a peerDependency, it is not automatically installed. Instead, the code that includes the package must include it as its dependency.

npm will warn you if you run npm install and it does not find this dependency.

Example: let’s say package a includes dependency b:

a/package.json

{
  //...
  "dependencies": {
    "b": "1.x"
  }
}

Package b in turn wants package c as a peerDependency:

b/package.json

{
  //...
  "peerDependencies": {
    "c": "1.x"
  }
}

In package A, we must therefore add c as a dependency, otherwise when you install package b, npm will give you a warning (and the code will likely fail at runtime):

a/package.json

{
  //...
  "dependencies": {
    "b": "1.x",
    "c": "1.x"
  }
}

The versions must be compatible, so if a peerDependency is listed as 2.x, you can’t install 1.x or another version. It all follows semantic versioning.

Lessons in this unit:

0: Introduction
1: How to use or execute a package installed using npm
2: npm dependencies and devDependencies
3: How to fix the "Missing write access" error when using npm
4: npm can install packages in the parent folder
5: Install an older version of an npm package
6: Find the installed version of an npm package
7: How to test an npm package locally
8: npm global or local packages
9: ▶︎ What are peer dependencies in a Node module?
10: `npm run dev` is a long-running program
11: Semantic Versioning using npm
12: Uninstalling npm packages with `npm uninstall`
13: An introduction to the npm package manager
14: The npx Node Package Runner
15: The package.json guide
16: The package-lock.json file
17: What is pnpm?
18: Should you commit the node_modules folder to Git?
19: Update all the Node dependencies to their latest version
20: Where does npm install the packages?
21: Bumping Node.js dependencies
22: Run package.json scripts upon any file changes in a folder