Reputation: 9261
I moved all database related operations into a standalone module:
@Module({
imports: [
TypeOrmModule.forFeature([
PostRepository,
UserRepository,
CommentRepository,
]),
],
exports: [PostRepository, UserRepository, CommentRepository],
providers: [PostsDataInitializer],
})
export class DatabaseModule {}
But in other modules, when I imported the DatabaseModule
and tried to inject PostRepository
in service class, I got the following error.
Nest cannot export a provider/module that is not a part of the currently processed module (DatabaseModule).
Please verify whether the exported PostRepository is available in this particular context.
Upvotes: 1
Views: 4438
Reputation: 9261
Resolved it myself after reading some of my Angular codes, just need to export the TypeOrmModule
in the DatabaseModule
.
@Module({
imports: [
TypeOrmModule.forFeature([
PostRepository,
UserRepository,
CommentRepository,
]),
],
exports: [TypeOrmModule],
providers: [PostsDataInitializer],
})
export class DatabaseModule {}
Upvotes: 11