Question
I downloaded an Angular project from GitHub and ran npm install, but npm showed many warnings like these:
npm WARN @angular/cdk@2.0.0-beta.10 requires a peer of @angular/core@^4.3.0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/forms@4.3.6 requires a peer of @angular/core@4.3.6 but none is installed. You must install peer dependencies yourself.
When I try to install the missing packages, the dependency list grows a lot, and some packages appear to require different versions of the same Angular packages.
Here is part of the warning output:
npm WARN @angular/animations@4.3.6 requires a peer of @angular/core@4.3.6 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/cdk@2.0.0-beta.10 requires a peer of @angular/core@^4.3.0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/cdk@2.0.0-beta.10 requires a peer of @angular/common@^4.3.0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/compiler@4.3.6 requires a peer of @angular/core@4.3.6 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/compiler-cli@4.3.6 requires a peer of @angular/core@4.3.6 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/forms@4.3.6 requires a peer of @angular/core@4.3.6 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/forms@4.3.6 requires a peer of @angular/common@4.3.6 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/forms@4.3.6 requires a peer of @angular/platform-browser@4.3.6 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/http@4.3.6 requires a peer of @angular/core@4.3.6 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/http@4.3.6 requires a peer of @angular/platform-browser@4.3.6 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/material@2.0.0-beta.10 requires a peer of @angular/core@^4.3.0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/material@2.0.0-beta.10 requires a peer of @angular/common@^4.3.0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/platform-browser-dynamic@2.4.10 requires a peer of @angular/compiler@2.4.10 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/platform-server@4.3.6 requires a peer of @angular/core@4.3.6 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/platform-server@4.3.6 requires a peer of @angular/common@4.3.6 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/platform-server@4.3.6 requires a peer of @angular/platform-browser@4.3.6 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/router@4.3.6 requires a peer of @angular/core@4.3.6 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/router@4.3.6 requires a peer of @angular/common@4.3.6 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/router@4.3.6 requires a peer of @angular/platform-browser@4.3.6 but none is installed. You must install peer dependencies yourself.
npm WARN angularfire2@2.0.0-beta.7-pre requires a peer of @angular/compiler@^2.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN extract-text-webpack-plugin@3.0.0 requires a peer of webpack@^3.1.0 but none is installed. You must install peer dependencies yourself.
My package.json includes Angular packages with different version ranges, for example:
{
"dependencies": {
"@angular/animations": "^4.0.0-rc.2",
"@angular/common": "^4.0.0-rc.2",
"@angular/compiler": "^4.0.0-rc.2",
"@angular/compiler-cli": "^4.0.0-rc.2",
"@angular/core": "^4.0.0-rc.2",
"@angular/flex-layout": "^2.0.0-rc.1",
"@angular/forms": "^4.0.0-rc.2",
"@angular/http": "^4.0.0-rc.2",
"@angular/material": "^2.0.0-beta.2",
"@angular/platform-browser": "^4.0.0-rc.2",
"@angular/platform-browser-dynamic": "^4.0.0-rc.2",
"@angular/platform-server": "^4.0.0-rc.2",
"@angular/router": "^4.0.0-rc.2"
},
"devDependencies": {
"@angular/cli": "^1.0.0-rc.1",
"@angular/compiler-cli": "^2.4.0",
"webpack": "^2.2.1"
}
}
Then ng serve fails with errors such as missing @angular/cdk/* modules and Angular Material API mismatches.
How should I fix this kind of npm peer dependency problem correctly?
Short Answer
By the end of this page, you will understand what peer dependencies are, why npm shows peer dependency warnings, and how version mismatches in Angular projects cause installation and build failures. You will also learn how to align package versions, inspect dependency requirements, and avoid mixing incompatible Angular ecosystem packages.
Concept
Peer dependencies are a way for one package to say: “I need you, the application, to provide another package at a compatible version.”
They are different from normal dependencies:
- A dependency is installed because a package directly needs it.
- A peer dependency means a package expects the host project to already have a matching version.
This matters a lot in frameworks like Angular, React, ESLint, and Webpack plugins, where many packages must work against the same shared core package.
In your example:
@angular/forms@4.3.6expects@angular/core@4.3.6@angular/cdk@2.0.0-beta.10expects@angular/core@^4.3.0@angular/platform-browser-dynamic@2.4.10expects@angular/compiler@2.4.10
That means the project is mixing:
- Angular 4 packages
- Angular 2 packages
- Angular Material/CDK packages from a different release line
- Tooling packages with incompatible versions
The real problem is not just missing packages. The real problem is an inconsistent dependency graph.
Why this matters in real programming:
- Framework ecosystems often require strict version alignment.
- A project may install successfully but still fail at runtime or build time.
- Warnings about peers often reveal deeper incompatibilities.
- Fixing one package manually can create more conflicts if the root versions are wrong.
In short: peer dependency warnings are often a sign that the project’s package.json needs cleanup and version alignment, not random package installs one by one.
Mental Model
Think of peer dependencies like a group project where everyone must agree on the same textbook edition.
@angular/coreis the textbook.- Packages like
@angular/forms,@angular/material, and@angular/routerare classmates. - Each classmate says, “I can work only if we all use edition 4.3.x.”
If one classmate brings edition 2.4, another brings edition 4.0 RC, and another expects edition 4.3.6, the group cannot work together.
So the solution is not to keep buying more textbooks. The solution is to make sure everyone uses the same compatible edition.
Syntax and Examples
In npm, peer dependency information is declared inside a package like this:
{
"name": "some-package",
"peerDependencies": {
"@angular/core": "^4.3.0"
}
}
This means:
- the package does not want its own separate copy of
@angular/core - your app must install a compatible version
Example of a compatible Angular setup
A healthy Angular project usually keeps Angular packages on the same version line:
{
"dependencies": {
"@angular/animations": "4.3.6",
"@angular/common": "4.3.6",
"@angular/compiler": "4.3.6",
"@angular/core": "4.3.6",
"@angular/forms": "4.3.6",
"@angular/http": "4.3.6",
"@angular/platform-browser": "4.3.6",
"@angular/platform-browser-dynamic": "4.3.6",
"@angular/router": "4.3.6",
"@angular/cdk": "2.0.0-beta.10",
"@angular/material": "2.0.0-beta.10"
}
}
Example of a broken setup
{
"dependencies": {
"@angular/core": "^4.0.0-rc.2",
"@angular/forms": "4.3.6",
"@angular/platform-browser-dynamic": "2.4.10",
"@angular/material": "^2.0.0-beta.2"
},
"devDependencies": {
"@angular/compiler-cli": "^2.4.0"
}
}
This is broken because:
- Angular core is on one release line
- forms is on another exact version
- platform-browser-dynamic is from Angular 2
- compiler-cli in
devDependenciesconflicts with compiler packages independencies - Material may expect a matching CDK package that is missing
Helpful commands
Check installed versions:
npm ls @angular/core
npm ls @angular/material
npm ls @angular/cdk
Inspect available or expected versions:
npm info @angular/material peerDependencies
npm info @angular/cdk peerDependencies
Clean install after fixing package.json:
rm -rf node_modules package-lock.json
npm install
These commands help you verify whether your dependency tree is consistent.
Step by Step Execution
Consider this simplified package.json:
{
"dependencies": {
"@angular/core": "4.3.6",
"@angular/forms": "4.3.6",
"@angular/material": "2.0.0-beta.10"
}
}
Suppose @angular/material@2.0.0-beta.10 has peer dependencies like:
{
"peerDependencies": {
"@angular/core": "^4.3.0",
"@angular/common": "^4.3.0",
"@angular/cdk": "2.0.0-beta.10"
}
}
Now walk through what happens:
- npm reads your project dependencies.
- It installs
@angular/core,@angular/forms, and@angular/material. - It notices that
@angular/materialexpects:@angular/core@angular/common@angular/cdk
- Your project has
@angular/core, so that part is okay. - Your project does not have
@angular/common, so npm warns. - Your project does not have
@angular/cdk, so npm warns. - If you then run the app, imports like
@angular/cdk/overlayfail because the package is not installed.
Now consider a version conflict:
{
"dependencies": {
"@angular/core": "4.3.6",
"@angular/platform-browser-dynamic": "2.4.10"
}
}
Step by step:
- npm installs both packages.
@angular/platform-browser-dynamic@2.4.10expects Angular 2-era compiler packages.- Your project is using Angular 4 core.
- The package tree becomes inconsistent.
- Build tools and TypeScript definitions no longer agree.
- You get errors during
ng serve.
The key lesson: npm warnings are often the first signal, but the actual breakage happens later during compilation or runtime.
Real World Use Cases
Peer dependencies appear often in real projects:
Frontend frameworks
- Angular packages must usually stay on the same major and often minor version.
- React plugins may require a specific React version.
- Vue tooling may require a compatible Vue core version.
Build tools
- Webpack plugins often expect a specific Webpack major version.
- ESLint plugins require a matching ESLint version.
- Babel plugins may require a specific Babel core version.
UI libraries
- Angular Material requires Angular CDK and compatible Angular core packages.
- Component libraries often depend on a host framework rather than bundling it themselves.
Monorepos and team projects
- A repo cloned from GitHub may install differently on a newer npm version.
- Old lockfiles and old package ranges may resolve to newer incompatible versions.
- Teams often pin versions to avoid accidental upgrades.
In all these cases, the practical fix is the same: use a compatible set of versions, not a random collection of latest packages.
Real Codebase Usage
In real codebases, developers handle dependency compatibility with a few common patterns.
1. Keep framework packages aligned
For Angular projects, teams usually pin all core Angular packages together:
{
"dependencies": {
"@angular/animations": "4.3.6",
"@angular/common": "4.3.6",
"@angular/compiler": "4.3.6",
"@angular/core": "4.3.6",
"@angular/forms": "4.3.6",
"@angular/http": "4.3.6",
"@angular/platform-browser": "4.3.6",
"@angular/platform-browser-dynamic": "4.3.6",
"@angular/router": "4.3.6"
}
}
This avoids subtle mismatches.
2. Match companion libraries deliberately
If using Angular Material, install the matching CDK version too:
{
"dependencies": {
"@angular/cdk": "2.0.0-beta.10",
"@angular/material": "2.0.0-beta.10"
}
}
3. Avoid duplicate declarations
A package like @angular/compiler-cli should not usually exist in conflicting versions across dependencies and devDependencies.
4. Clean reinstall after version changes
Developers often remove old artifacts before reinstalling:
rm -rf node_modules package-lock.json
npm install
5. Use package inspection as a guard clause
Before upgrading, developers check peer requirements first:
npm info some-package peerDependencies
6. Prefer exact or carefully pinned versions in older projects
Old projects often break when ^ ranges pull in newer releases than the code originally expected. Pinning versions is safer when reviving archived repositories.
7. Upgrade in groups, not one package at a time
For framework ecosystems, upgrades are usually done as a set:
- Angular core packages together
- Angular Material with CDK
- CLI with compiler and TypeScript compatibility
- Build plugins with the right Webpack version
Common Mistakes
1. Installing peer dependencies one by one without checking the bigger picture
Beginners often see a warning and immediately install the missing package.
npm install @angular/core
npm install @angular/common
npm install @angular/compiler
This can make things worse if versions do not match.
Better approach
- Inspect the project’s version set first
- Choose one compatible version line
- Update
package.jsonas a whole
2. Mixing Angular major or minor versions
Broken example:
{
"dependencies": {
"@angular/core": "4.3.6",
"@angular/forms": "4.3.6",
"@angular/platform-browser-dynamic": "2.4.10"
}
}
Why it fails:
- Angular packages are meant to work together in matching versions
3. Forgetting required peer packages like CDK
Broken example:
{
"dependencies": {
"@angular/material": "2.0.0-beta.10"
}
}
Why it fails:
- Angular Material depends on Angular CDK as a peer
- Build errors such as
Cannot find module '@angular/cdk/...'appear
4. Keeping conflicting versions in dependencies and devDependencies
Broken example:
{
"dependencies": {
"@angular/compiler-cli": "^4.0.0-rc.2"
},
"devDependencies": {
"@angular/compiler-cli": "^2.4.0"
}
}
Why it fails:
- npm resolves a dependency tree that may not match your app code or build tools
5. Trusting ^ ranges in old projects
Example:
{
"@angular/core": "^4.0.0-rc.2"
}
This can resolve to a later version than the original author tested.
Better approach
Use exact versions for restoration work:
{
"@angular/core": "4.3.6"
}
6. Ignoring build errors after installation warnings
Warnings are easy to dismiss, but they often predict the exact compile errors you later see.
If you see:
- missing module errors
- API differences like
forRootno longer existing - stylesheet import failures
then the dependency versions are probably incompatible.
Comparisons
| Concept | What it means | Who installs it | Typical use |
|---|---|---|---|
dependencies | Packages your app directly needs | npm installs them for your app | Angular, RxJS, Lodash |
devDependencies | Packages used for development/build/test | npm installs for development | CLI, test runners, TypeScript |
peerDependencies | Packages a library expects the host app to provide | Usually your app must provide them | Angular core for Angular plugins |
Peer dependency vs normal dependency
| Feature | Dependency | Peer dependency |
|---|---|---|
| Installed automatically by package itself | Yes | Not always, especially in older npm behavior |
| Separate copy allowed | Often yes | Usually not the intention |
| Best for shared framework package | No | Yes |
| Example | lodash inside your app | @angular/core required by @angular/forms |
Compatible vs incompatible Angular setup
| Setup | Result |
|---|---|
All Angular packages on 4.3.6 | Usually stable |
Some Angular packages on 4.3.6, some on 2.4.10 | Broken build likely |
| Angular Material installed without CDK | Missing module errors |
| Webpack plugin for v3 with Webpack v2 | Tooling conflict |
Warning vs error
| Type | Meaning |
|---|---|
| npm warning | Something is missing or mismatched, but install may continue |
| build error | The code or toolchain actually cannot compile or run |
In your case, the warnings led to real build errors because the project’s package versions do not agree.
Cheat Sheet
Peer dependency quick reference
- A peer dependency means: “your project must install this package too.”
- Common in Angular, React, ESLint, Webpack plugins, and UI libraries.
- Peer warnings often mean version mismatch, not just missing packages.
Angular rule of thumb
Keep these on the same version:
@angular/animations
@angular/common
@angular/compiler
@angular/core
@angular/forms
@angular/http
@angular/platform-browser
@angular/platform-browser-dynamic
@angular/router
Angular Material rule of thumb
Install matching versions of:
@angular/material
@angular/cdk
Useful commands
npm ls @angular/core
npm info @angular/material peerDependencies
npm info @angular/cdk peerDependencies
rm -rf node_modules package-lock.json
npm install
Safe recovery steps
- Open
package.json - Remove conflicting duplicate versions
- Align Angular package versions
- Add required peer packages like
@angular/cdk - Clean reinstall
- Run build again
Red flags
- Angular 2 and Angular 4 packages mixed together
- Same package listed with different versions in dependencies/devDependencies
- Missing
@angular/cdkwhen using Angular Material - Old project using loose
^ranges
Practical fix for this specific kind of issue
- Choose one Angular version line
- Pin all Angular packages to it
- Match Material and CDK versions
- Match build tools to plugin requirements
- Do not fix peers package by package without checking compatibility
FAQ
What does “requires a peer of ... but none is installed” mean?
It means a package expects your project to provide another package at a compatible version, but npm did not find it in your app.
Are peer dependency warnings safe to ignore?
Sometimes, but often not. In framework-based projects, they frequently lead to build or runtime failures.
Why does Angular break when package versions do not match?
Angular packages are designed to work together in aligned versions. Mixing major or minor versions can cause API, type, and compiler incompatibilities.
Why is @angular/cdk missing when I installed @angular/material?
Because Angular Material expects CDK as a peer dependency. Your app must install the matching CDK version explicitly.
Should I install every missing peer manually?
Not blindly. First inspect all package versions and choose a compatible set. Installing one missing peer at a time can create more conflicts.
Why did ng serve fail even though npm install completed?
Because npm warnings do not always stop installation. The real incompatibility may appear later when TypeScript, Angular compiler, or Webpack tries to build the app.
Should I use exact versions or caret (^) ranges?
For older or archived projects, exact versions are usually safer. Caret ranges can pull in newer versions than the original code expected.
How do I fix an old GitHub project with dependency issues?
Check the original framework version, align all related packages, remove node_modules and lockfiles, reinstall, and only then try to run the app.
Mini Project
Description
You are restoring an older Angular project that no longer installs cleanly. The project shows peer dependency warnings and missing module errors for Angular Material and CDK. This mini project demonstrates how to audit a broken package.json, align related package versions, and produce a dependency setup that can install more reliably.
Goal
Create a cleaned-up package.json dependency section where Angular packages, Angular Material/CDK, and tooling versions are internally consistent.
Requirements
- Identify at least one conflicting package version in the Angular dependency set.
- Add any missing peer dependency required by Angular Material.
- Remove or correct at least one duplicate or conflicting version declaration.
- Pin Angular-related packages to one compatible version line.
- Show the cleanup steps needed before reinstalling packages.
Keep learning
Related questions
@Directive vs @Component in Angular: Differences, Use Cases, and When to Use Each
Learn the difference between @Directive and @Component in Angular, including use cases, examples, and when to choose each.
Accessing Input Value from EventTarget in TypeScript
Learn why EventTarget has no value property in TypeScript and safely read values from HTML input events in Angular applications.
Angular (change) vs (ngModelChange): What’s the Difference?
Learn the difference between Angular (change) and (ngModelChange), when each fires, and which one to use in forms and inputs.