1

In our code, we use node 14.17.6 and want to upgrade v18.16.1. But when we upgrade and run npm install it is showing following error:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @nestjs/graphql@10.1.1
npm ERR! Found: ts-morph@10.1.0
npm ERR! node_modules/ts-morph
npm ERR!   ts-morph@"^10.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional ts-morph@"^13.0.2 || ^14.0.0 || ^15.0.0" from @nestjs/graphql@10.1.1
npm ERR! node_modules/@nestjs/graphql
npm ERR!   @nestjs/graphql@"^10.1.1" from the root project
npm ERR!   peer @nestjs/graphql@"^10.0.0" from @nestjs/apollo@10.1.0
npm ERR!   node_modules/@nestjs/apollo
npm ERR!     @nestjs/apollo@"^10.1.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: ts-morph@15.1.0
npm ERR! node_modules/ts-morph
npm ERR!   peerOptional ts-morph@"^13.0.2 || ^14.0.0 || ^15.0.0" from @nestjs/graphql@10.1.1
npm ERR!   node_modules/@nestjs/graphql
npm ERR!     @nestjs/graphql@"^10.1.1" from the root project
npm ERR!     peer @nestjs/graphql@"^10.0.0" from @nestjs/apollo@10.1.0
npm ERR!     node_modules/@nestjs/apollo
npm ERR!       @nestjs/apollo@"^10.1.0" from the root project
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.
npm ERR!

I have updated ts-morph from 10.1.0 to 13.0.2. But not working, it then showing other dependency error.

our current version:

    "@apollo/gateway": "^2.1.1",
    "@nestjs/apollo": "^10.1.0",
    "@nestjs/common": "^9.0.11",
    "@nestjs/config": "^2.2.0",
    "@nestjs/core": "^9.0.11",
    "@nestjs/graphql": "^10.1.1",
    "@newrelic/apollo-server-plugin": "^2.0.1",
    "apollo-server-express": "^3.10.2",
    "apollo-server-plugin-query-complexity": "^1.0.0",
    "graphql": "^16.6.0",

I have also used ncu and try following ncu -u. It is updating all npm package version. Then run npm i, but not working.

It shows following result:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: user-service@0.0.1
npm ERR! Found: @nestjs/apollo@10.1.0
npm ERR! node_modules/@nestjs/apollo
npm ERR!   @nestjs/apollo@"^12.0.7" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! @nestjs/apollo@"^12.0.7" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @nestjs/common@10.1.0
npm ERR! node_modules/@nestjs/common
npm ERR!   peer @nestjs/common@"^9.3.8 || ^10.0.0" from @nestjs/apollo@12.0.7
npm ERR!   node_modules/@nestjs/apollo
npm ERR!     @nestjs/apollo@"^12.0.7" from the root project
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.
sonnet
  • 15
  • 4
  • Don't be afraid to trust the error messages. It says use `npm i --legacy-peer-deps`. This usually works, and will b an annoying necessity probably for a few years. – Zac Anger Jul 19 '23 at 03:43
  • You can remove `ts-morph` (and other peer dependencies you added due to legacy resolution of old NPM version) from the root project and let NPM install the correct versions for you. You can also use `--force` to allow NPM to try to force install a sensible set of peer deps. Older versions of npm did not install the peer dependencies at all and newer versions treat them as dependencies so this surfaces potential issues in the packages that specify them – apokryfos Jul 19 '23 at 03:45

1 Answers1

1

Sometimes it is extremely hard to resolve dependency if you are trying to update every package to the latest version. If you are using VS code, first install Version Lens in vs code, then try to update npm version to statisfies not latest. I believe you will be able to upgrade everything.

sabbir
  • 2,020
  • 3
  • 26
  • 48