Search code examples
javascriptangularangular-materialnestpeer-dependencies

How do I resolve peer dependency conflicts with Nx, Angular and Nest?


I have a pretty fresh Nx workspace. Created an Angular app and a Nest app a few months ago, no problems. I come back after a hiatus to start a new Angular app and now I have a bunch of peer dependency conflicts I don't know how to resolve. I've tried adding the --legacy-peer-deps option to npm install and this works (4 high vulnerabilities) but when I try to run npx nx g @angular/material:ng-add I can't get around the errors.

Errors below:

npm ERR! While resolving: @nestjs/[email protected]
npm ERR! Found: @nestjs/[email protected]
npm ERR! node_modules/@nestjs/common
npm ERR!   @nestjs/common@"^8.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @nestjs/common@"^7.0.0" from @nestjs/[email protected]
npm ERR! node_modules/@nestjs/core
npm ERR!   @nestjs/core@"^7.5.5" from the root project
npm ERR!   peer @nestjs/core@"^7.0.0" from @nestjs/[email protected]
npm ERR!   node_modules/@nestjs/platform-express
npm ERR!     @nestjs/platform-express@"^7.5.5" from the root project
npm ERR!     2 more (@nestjs/core, @nestjs/testing)
npm ERR!   1 more (@nestjs/testing)
npm ERR!
npm ERR! Conflicting peer dependency: @nestjs/[email protected]
npm ERR! node_modules/@nestjs/common
npm ERR!   peer @nestjs/common@"^7.0.0" from @nestjs/[email protected]
npm ERR!   node_modules/@nestjs/core
npm ERR!     @nestjs/core@"^7.5.5" from the root project
npm ERR!     peer @nestjs/core@"^7.0.0" from @nestjs/[email protected]
npm ERR!     node_modules/@nestjs/platform-express
npm ERR!       @nestjs/platform-express@"^7.5.5" from the root project
npm ERR!       2 more (@nestjs/core, @nestjs/testing)
npm ERR!     1 more (@nestjs/testing)
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.

Solution

  • I'm not too sure how it ended up working out, but I just slowly dialed back my conflicting dependencies to previous versions until there were no dependency conflicts. This resulted in 8 high vulnerabilities, then I ran npm audit fix --force and it removed all vulnerabilities.

    Just to make sure, I updated Nx (according to their docs) and now I don't have anymore issues or warnings or errors.

    If someone knows why this resolved my issue, I would love to hear the explanation.