Module makes injectables undefined with WebSocketGateway

33 Views Asked by At

When injecting a specific module in a WebSocketGateway (or a module injecting it), all of my injectables are undefined.

I got the issue with the UnleashModule from nestjs-unleash. I posted an issue here : https://github.com/pmb0/nestjs-unleash/issues/493.

If I remove the injectable, others are working as intended. I don't know if the issue is related to WebSocketGateway but I only had it with WebSocketGateway.

I was expecting my other injectable not to be undefined, I tried to remove every other injectable but this one and a debugger to see if it does the same :

@WebSocketGateway({
    path: '/ws/v2',
})
export class WsGateway {
    @WebSocketServer()
    server: Server;

    constructor(
        private readonly debuggerService: DebuggerService,
        private readonly featureFlagService: UnleashModule,
    ) {}

    handleConnection(client: Socket) {
        this.debuggerService.info({
            message: `Socket connected:  ${client.id} `,
        });
    }

    handleDisconnect(client: Socket) {
        this.debuggerService.info({
            message: `Socket disconnected:  ${client.id} `,
        });
    }
}

Edit : The gateway is directly injected in my AppModule :

@Module({
    controllers: [],
    imports: [
        WsGatewaysModule,
        CoreModule.register({
            configs,
            i18nPath: path.join(__dirname, '../i18n/'),
        }),
        // ...
        FeatureFlagModule.registerAsync({
            useFactory: (configService: ConfigService) => ({
                appName: 'studio',
                url: configService.get('...'),
                instanceId: configService.get('...'),
                http: {
                    headers: {
                        Authorization: configService.get('...'),
                    },
                },
                userIdFactory: (req) => req[USER_INFO_CONTEXT_PROPERTY]?.userId,
            }),
            inject: [ConfigService],
        }),
        RouterModule.forRoot(),
        FeatureModule,
        UserInfoModule,
        TrackingModule,
    ],
})
export class AppModule {}

The FeatureFlagModule is the one injecting UnleashModule

0

There are 0 best solutions below