#Error in injecting Services in WebSocket
18 messages · Page 1 of 1 (latest)
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
Something sounds wrong. Can you provide a reproduction?
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?)
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")
})
);
}
there is no dependency on chatgateway
Do any of those inject REQUEST?
in userService we use request
Does it inject it?
yess
Then ChatService and therefore ChatGateway is indeed REQUEST scoped, which is not doable
@worthy beacon - for the future... 🙂
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);
}
}
Thank you i'll keep in mind for next time👀
👍🏻