【发布时间】:2023-02-04 23:50:41
【问题描述】:
我有一个类结构是这样的:
我在 libs/childmodule/src/child.module.ts 中有一个 ChildModule。我有一个 taconfig.json,它映射到 @app。
然后我有一个 parentModule,我试图在其中导入 ChildModule。代码:
ChildModule:
import { Module } from '@nestjs/common';
import { ChildService } from './child.service';
import { LoggerModule } from '@app/logger';
import { CommonModule } from '@app/common';
import { SecretsModule } from '@app/secrets';
@Module({
providers: [ChildService],
exports: [ChildService],
imports: [
LoggerModule,
CommonModule,
SecretsModule,
],
})
export class AuditModule {}
我的ParentModule如下:
import { ChildModule } from '@app/child';
@Module({
imports: [SomeModule, LoggerModule, ChildModule],
controllers: [ParentController],
providers: [ParentService],
exports: [ParentService],
})
export class ParentModule {}
我什至还没有通过 DI 使用这个ChildSevice。
我得到的错误:
Error: Nest can't resolve dependencies of the ChildService (LoggerService, CommonService, ?). Please make sure that the argument SecretsService at index [2] is available in the AuditModule context.
Potential solutions:
- If SecretsService is a provider, is it part of the current AuditModule?
- If SecretsService is exported from a separate @Module, is that module imported within AuditModule?
@Module({
imports: [ /* the Module containing SecretsService */ ]
})
据我所知,如果我可以将一个模块(在我的例子中是 ChildModule)导入父模块,那么所有 ChildModule 依赖项都将得到解决。我的意思是我不需要手动在父模块的提供者中提及 ChildModule 的所有依赖项。
无法得到任何线索这里缺少什么。
【问题讨论】:
标签: typescript ts-jest