#Error in injecting Services in WebSocket

18 messages · Page 1 of 1 (latest)

hollow goblet
#
  1. you don't need @Injectable()
  2. ChatService isn't REQUEST scoped, is it?
worthy beacon
#

no chat service is normal class

#

even if i make new logger it is also giving same error cannot read properties of undefined this.logger.log

hollow goblet
#

Something sounds wrong. Can you provide a reproduction?

exotic drift
#

Cannot read properties of undefined
This usually means Nest did not inject the dependency, because it couldn't find any metadata on the class. That's usually causes by a circular reference between files (likely the ChatGateway and ChatService - are you sure they don't reference each other?)

worthy beacon
#

in my chatservice i have this code injected
constructor(
config: ConfigService,
private redisMgr: ChatCache,
private vectorService: VectorService,
private usageService: UsageService,
private userService: UserService,
@InjectQueue(QueueName.InteractionLogUsage) private interactionLogUsageQueue: Queue,
@InjectQueue(QueueName.NewLeadNotification) private newLeadQueue: Queue
) {
this.oaiClient = new OpenAIApi(
new Configuration({
apiKey: config.get<string>("OPENAI_API_KEY")
})
);
}

worthy beacon
hollow goblet
worthy beacon
#

in userService we use request

hollow goblet
#

Does it inject it?

worthy beacon
#

yess

hollow goblet
#

Then ChatService and therefore ChatGateway is indeed REQUEST scoped, which is not doable

worthy beacon
#

alrighty i guess that's why it is not working in gateway

#

thanks for the help

honest grotto
#

@worthy beacon - for the future... 🙂

tawny etherBOT
#

Please format your question or answer with Markdown formatting.
It leads to better readability and an easier time to spot problems.
For code blocks, you can wrap your block with three back ticks before and after the block, and after the first three back ticks you can add a language (like ts) to add syntax highlighting.
e.g.

```ts
@Injectable()
export class MySuperAwesomeService {
constructor(@Inject('InjectionToken') private readonly dep: SomeDependency) {}

getRandomNumber(): number {
return Math.round(Math.random() * 1000);
}
}
```

Becomes :point_down:

@Injectable()
export class MySuperAwesomeService {
  constructor(@Inject('InjectionToken') private readonly dep: SomeDependency) {}

  getRandomNumber(): number {
    return Math.round(Math.random() * 1000);
  }
}
worthy beacon
#

Thank you i'll keep in mind for next time👀

honest grotto
#

👍🏻