node.jsnpmdependenciesazure-pipelineshandsontable

How to use npm install without the --legacy-peer-deps flag to resolve a conflicting peer dependency?


I am having trouble with a peer dependcy called zone.js. Version ^0.8.19 is required for @handsontable/angular but version ~0.10.2 is required for @angular/core and others. I get this error message when I try npm install.

While resolving: @angular/core@9.0.7
npm ERR! Found: zone.js@0.8.29
npm ERR! node_modules/zone.js
npm ERR!   zone.js@"^0.8.19" from the root project
npm ERR!   peer zone.js@"^0.8.19" from @handsontable/angular@2.0.0
npm ERR!   node_modules/@handsontable/angular
npm ERR!     @handsontable/angular@"2.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer zone.js@"~0.10.2" from @angular/core@9.0.7
npm ERR! node_modules/@angular/core
npm ERR!   @angular/core@"~9.0.1" from the root project
npm ERR!   peer @angular/core@"9.0.7" from @angular/animations@9.0.7
npm ERR!   node_modules/@angular/animations
npm ERR!     @angular/animations@"~9.0.1" from the root project
npm ERR!     2 more (@angular/material, @angular/platform-browser)
npm ERR!   10 more (@angular/cdk, @angular/common, @angular/forms, ...)
npm ERR!
npm ERR! Conflicting peer dependency: zone.js@0.10.3
npm ERR! node_modules/zone.js
npm ERR!   peer zone.js@"~0.10.2" from @angular/core@9.0.7
npm ERR!   node_modules/@angular/core
npm ERR!     @angular/core@"~9.0.1" from the root project
npm ERR!     peer @angular/core@"9.0.7" from @angular/animations@9.0.7
npm ERR!     node_modules/@angular/animations
npm ERR!       @angular/animations@"~9.0.1" from the root project
npm ERR!       2 more (@angular/material, @angular/platform-browser)
npm ERR!     10 more (@angular/cdk, @angular/common, @angular/forms, ...)
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Attempt #1 Update package.json After deleting package-lock.json and node_modules I tried npm install with the updated version shown below. My understanding is that the ^0.8.19 should include 0.8.19 to <1.0.0. Wouldn't 0.10.2 fall in this range?

 "dependencies": {
    ...
    "zone.js": "^0.8.19"
  },

Attempt #2 --legacy-peer-deps I want to avoid using this flag because this ultimately runs in a pipeline without the flag. Would updating the command to npm install --legacy-peer-deps be risky or dangerous? I have little experience with pipelines and all the senior devs who set this up quit :(


Solution

  • You have the option to retry with --force to bypass the conflict or --legacy-peer-deps command to ignore peer dependencies entirely.

    By default, In the new version of npm (v7), npm install will fail when it encounters conflicting peerDependencies. It was not like that before.

    The differences between the two are below -

    --legacy-peer-deps: ignore all peerDependencies when installing, in the style of npm version 4 through version 6.

    --strict-peer-deps: fail and abort the install process for any conflicting peerDependencies when encountered. By default, npm will only crash for peerDependencies conflicts caused by the direct dependencies of the root project.

    --force: will force npm to fetch remote resources even if a local copy exists on disk.