Reputation: 379
I have a problem while was working with nestjs HttpModule
The error:
Nest can't resolve dependencies of the ShopService (PrismaService, ?). Please make sure that the argument HttpService at index [1] is available in the QaModule context.
My ShopModule:
@Module({
imports: [HttpModule],
controllers: [ShopController],
providers: [ShopService, PrismaService],
})
export class ShopModule {}
My QaModule:
@Module({
controllers: [QaController],
providers: [QaService, PrismaService, ShopService],
})
export class QaModule {}
What are the solutions?
Upvotes: 2
Views: 1396
Reputation: 70131
Change your ShopModule
to
@Module({
imports: [HttpModule],
controllers: [ShopController],
providers: [ShopService, PrismaService], // Prisma Service should probably come from PrisamModule
exports: [ShopService],
})
export class ShopModule {}
and your QaModule
to
@Module({
imports: [ShopModule],
controllers: [QaController],
providers: [QaService, PrismaService], // Prisma Service should still probably come from `PrismaModule`
})
export class QaModule {}
Services should only be declared in one module and then exported from that module if they need to be used elsewhere. In the module that declares the consuming service, the original module should be added to the imports
array. This will ensure you have only one instance of each non-transient provider and will not need to be recreated in each module it is used in
Upvotes: 6