I am trying to use a typeorm custom repository defined in another module.
Following the documentation:
If you want to use the repository outside of the module which imports TypeOrmModule.forFeature, you'll need to re-export the providers generated by it. You can do this by exporting the whole module, like this:
@Module({
imports: [TypeOrmModule.forFeature([Role])],
exports: [TypeOrmModule]
})
export class RoleModule {}
Now if we import UsersModule in UserHttpModule, we can use @InjectRepository(User) in the providers of the latter module.
In my case i do:
@Module({
imports: [RoleModule],
providers: [UsersService],
controllers: [UsersController]
})
export class UserModule {}
Now when i inject the Role repository
export class UserService {
constructor(@InjectRepository(Role) private roleRepository: Repository<Role>) {}
}
i've got an error:
Nest can't resolve dependencies of the UserService (?).
Is it me or is the documentation incorrect? Can someone suggest what is the error here or give a corrected example?
[ExceptionHandler] Nest can't resolve dependencies of the UserService (?). Please make sure that the argument RoleRepository at index [1] is available in the UserModule context. Potential solutions: - If RoleRepository is a provider, is it part of the current UserModule? - If RoleRepository is exported from a separate @Module, is that module imported within UserModule? @Module({ imports: [ /* the Module containing RoleRepository */ ] })
– Odeus