To better understand the issue at hand, let's delve into the error message:
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f080829f9a959384dd91949d999eb0c1c1dec0dec0">[email protected]</a>
npm ERR! Found: @angular/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6a0905070705042a5b5b445a4459">[email protected]</a>
npm ERR! node_modules/@angular/common
npm ERR! @angular/common@"11.0.3" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/common@"^9.1.0 || ^10.0.0" from @agm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a0c3cfd2c5e0938e908e908dc2c5d4c18e90">[email protected]</a>
npm ERR! node_modules/@agm/core
npm ERR! @agm/core@"3.0.0-beta.0" from the root project
The key is to analyze the problem starting from the bottom up. It appears that @agm/[email protected] requires either angular common version 9.1.0 or 10.0.0. However, the currently detected angular common version is actually 11.0.3.
(For a clearer understanding of dependencies, check out this simple site: How npm3 Works)
dependencies — these are the essential dependencies that you rely on and call in your project’s code
devDependencies — these are your development dependencies, for example, a prettier library for formatting code
peerDependencies — if you set a peer dependency in your package.json, you are telling the person who installs your package that they need that dependency with the specified version
optionalDependencies — these dependencies are optional and failing to install them will not break the installation process
bundledDependencies — it’s an array of packages that will come bundled with your package. This is useful when some 3rd party library is not on NPM, or you want to include some of your projects as modules
So what's the solution? The core issue lies within the peer dependencies. To resolve this, you can either downgrade angular common or utilize legacy dependencies logic by using --legacy-peer-deps flag during package installation. Enabling --legacy-peer-deps prevents automatic installation of peerDependencies. Will this fix your problem? Most likely yes, but specific instructions should be given on how to proceed. Alternatively, you can make use of the following command mentioned in a previous answer:
npm config set legacy-peer-deps true
In my personal experience, without setting the configuration above, I encountered missing dependency packages while running ng serve due to --legacy-peer-deps usage. I had to manually install those missing packages. After installing approximately five packages manually with --legacy-peer-deps, there was one package that could not be installed, leading me to abandon its use and seek an alternative.
Other potential solutions I came across include:
- Downgrading Node.js to v14 to also downgrade npm, which seemed to assist many users.
- Using Yarn to enforce package installation - although unfamiliar with the process myself.
- Lowering the versions of Angular and global Angular CLI to fulfill requirements.
- Exploring if updating all packages using helps, especially for new projects.