nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.73k stars 7.63k forks source link

@Req still undefinied with reflect-metadata@^0.2 #13322

Closed gayamedj closed 8 months ago

gayamedj commented 8 months ago

Is there an existing issue for this?

Current behavior

Last week, I had a problem with the @req object being undefined. I discovered that the issue was related to the reflect-metadata version not matching the one used by the typeorm package. To address this, I downgraded typeorm to version 0.3.19, which resolved the issue.

However, today, I encountered the same problem again, and unfortunately, the previous solution didn't work. After seeking help on the support channel, I learned of another solution that seemed to work for others: upgrading the reflect-metadata version to ^0.2.1. Despite trying this, my @req#3382 body remains undefined.

  "dependencies": {
    "@hapi/joi": "^17.1.1",
    "@nestjs/common": "^10.3.3",
    "@nestjs/config": "^3.2.0",
    "@nestjs/core": "^10.3.3",
    "@nestjs/mapped-types": "^2.0.5",
    "@nestjs/platform-express": "^10.0.0",
    "@nestjs/platform-fastify": "^10.3.3",
    "@nestjs/typeorm": "^10.0.2",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.14.1",
    "mysql2": "^3.9.2",
    "reflect-metadata": "^0.2.1",
    "rxjs": "^7.8.1",
    "typeorm": "^0.3.20"
  },

Minimum reproduction code

https://github.com/gayamedj/nestjs-reflect-metadata-version-issue

Steps to reproduce

  1. yarn start
  2. Send a POST request to the "/admins" route with JSON Body

Expected behavior

The route should return the body you sent.

Package

Other package

No response

NestJS version

No response

Packages versions

{ "@hapi/joi": "^17.1.1", "@nestjs/common": "^10.3.3", "@nestjs/config": "^3.2.0", "@nestjs/core": "^10.3.3", "@nestjs/mapped-types": "^2.0.5", "@nestjs/platform-express": "^10.0.0", "@nestjs/platform-fastify": "^10.3.3", "@nestjs/typeorm": "^10.0.2", "class-transformer": "^0.5.1", "class-validator": "^0.14.1", "mysql2": "^3.9.2", "reflect-metadata": "^0.2.1", "rxjs": "^7.8.1", "typeorm": "^0.3.20" }

Node.js version

v20.11.0

In which operating systems have you tested?

Other

No response

micalevisk commented 8 months ago

I didn't manage to reproduce it with this minimum repro https://gitlab.com/micalevisk/reflecting

kamilmysliwiec commented 8 months ago

Let's track this here https://github.com/typeorm/typeorm/issues/10671

OSA413 commented 7 months ago

Can not reproduce, package-lock file shows "reflect-metadata": "^0.2.1"