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"
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.
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":
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.
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"
}
}
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:
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 |
|---|
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
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 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.
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.
Angular @ViewChild Returning Undefined: Lifecycle, Child Components, and Fixes
Learn why Angular @ViewChild can be undefined, when it becomes available, and how to access child components correctly using lifecycle hooks.