nestjs / typeorm

TypeORM module for Nest framework (node.js) πŸ‡
https://nestjs.com
MIT License
1.91k stars 206 forks source link

TypeOrmModule makes @Request() unusable #1887

Closed klu2 closed 7 months ago

klu2 commented 7 months ago

Is there an existing issue for this?

Current behavior

I do have a quite simple Nest.js application, running on the latest version (10.3.1, but also tried with 10.0.1).

I have a controller which uses @Request as method parameters like that:

@Get('/')
@Render('index')
async index(@Request() req) {
    const user = req.user as User;
    :
}

That worksperfectly fine, but as soon as I import a TypeOrmModule like that into my AppModule

@Module({
    imports: [
        ConfigModule.forRoot(),
        TypeOrmModule.forRoot({
            type: 'postgres',
            username: 'admin',
            password: 'admin',
            database: 'my_db',            
            synchronize: false,
        }),
    ],
    controllers: [AppController],
    providers: [],
})
export class AppModule {}

then the req in the controller from above is always undefined. There is some magic in the background by TypeOrmModule which disables this method argument resolution and tbh I have no idea why.

Minimum reproduction code

https://github.com/klu2/nest-typeorm-bug

Steps to reproduce

  1. npm install
  2. npm run start
  3. open localhost:3000 --> you see the text Hello, localhost, coming from AppController
  4. uncomment the import to TypeOrmModule in AppModule and a just the database settings to a postgres database which exists on your machine
  5. restart the server, again navigate ro localhost:3000 --> you will see 'Hello, undefined', as now `req in AppControllerdoes not have a value anymore

Expected behavior

The @Req() req: Request also works when typeorm from support nest.js is active

Package version

10.0.1

NestJS version

10.0.0

Node.js version

21

In which operating systems have you tested?

Other

No response

kamilmysliwiec commented 7 months ago

Thank you for taking the time to submit your report! From the looks of it, this could be better discussed on our Discord. If you haven't already, please join here and send a new post in the #⁠ 🐈 nestjs-help forum. Make sure to include a link to this issue, so you don't need to write it all again. We have a large community of helpful members, who will assist you in getting this to work.