-
Why do I get "Cannot read properties of undefined (reading 'get')" in NestJS? |
Beta Was this translation helpful? Give feedback.
Answered by
TatyOko28
Feb 9, 2025
Replies: 1 comment
-
This occurs when a service or dependency is not properly initialized. Solution: Ensure the service is correctly injected: @Controller("users")
export class UserController {
constructor(private readonly userService: UserService) {}
@Get()
getUsers() {
return this.userService.getAllUsers(); // Ensure userService is initialized
}
} Ensure UserService is declared in providers: @Module({
providers: [UserService],
controllers: [UserController],
})
export class UserModule {} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Tanu-N-Prabhu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This occurs when a service or dependency is not properly initialized.
Solution: Ensure the service is correctly injected:
Ensure UserService is declared in providers:
@Module({ providers: [UserService], controllers: [UserController], }) export class UserModule {}