Search code examples
nestjsnestjs-config

Resolving NestJS dependency


I have encountered this error when trying to execute npm install @nestjs/microservices:

# npm resolution error report

While resolving: [appName]
Found: @nestjs/common@9.4.3
node_modules/@nestjs/common
  @nestjs/common@"^9.4.3" from the root project

Could not resolve dependency:
peer @nestjs/common@"^10.0.0" from @nestjs/microservices@10.1.3
node_modules/@nestjs/microservices
  @nestjs/microservices@"*" from the root project

Fix the upstream dependency conflict, or retry
this command with --force or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.

These are my dependencies in package.json :

"dependencies": {
    "@nestjs/cache-manager": "^2.1.0",
    "@nestjs/common": "^9.4.3",
    "@nestjs/config": "^3.0.0",
    "@nestjs/core": "^9.0.0",
    "@nestjs/passport": "^10.0.0",
    "@nestjs/platform-express": "^9.4.3",
    "@nestjs/swagger": "^7.0.12",
    "@nestjs/typeorm": "^10.0.0",
    "bcryptjs": "^2.4.3",
    "cache-manager": "^5.2.3",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.14.0",
    "dotenv": "^16.3.1",
    "express-session": "^1.17.3",
    "jsonwebtoken": "^9.0.0",
    "passport": "^0.6.0",
    "passport-google-oauth20": "^2.0.0",
    "pg": "^8.11.1",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^7.2.0",
    "typeorm": "^0.3.17"
  },

I tried using --legacy-peer-deps but it wont compile and i don't want to use --force. If anyone had idea what to fix, I would be extremely grateful.


Solution

  • You are trying to install a v10 NestJS package while in your project you're using v9; you can safely install @nestjs/microservices 9.4.3 with

    npm install @nestjs/microservices@^9.4.3

    or upgrade actual packages to v10 (some changes to the code could be mandatory).