I have a service that uses moduleRef for dynamic resolving dependencies. That works fine for me.
@Injectable()
export class BootstrappingService {
constructor(private readonly moduleRef: ModuleRef) {
this.logger.setContext(BootstrappingService.name);
}
bindCommand(string commandName): void {
const reference = this.moduleRef.get(commandName, { strict: false });
//...
this.logger.log(`Command "${commandName}" bound to this service.`);
}
}
Whatever I define in other parts of the implementations and call this method, it finds the correct reference with its dependencies and load it for me. The moduleRef
dependency works fine too.
Now I’m trying to create integration tests for this particular project. However, when I use TestingModule
to create an instance of my service, it throws me a moduleRef
error:
I’m creating my module like the following:
const serviceModule = await Test.createTestingModule({
imports: [MyServiceModule],
}).compile();
Then this error is thrown to me:
Nest can't resolve dependencies of the BootstrappingService (?). Please make sure that the argument ModuleRef at index [0] is available in the BootstrappingModule context.
Potential solutions:
- Is BootstrappingModule a valid NestJS module?
- If ModuleRef is a provider, is it part of the current BootstrappingModule?
- If ModuleRef is exported from a separate @Module, is that module imported within BootstrappingModule?
@Module({
imports: [ /* the Module containing ModuleRef */ ]
})
Do you know what I am missing that moduleRef
is not properly injected?
Those are the package versions I’m using atm:
"@nestjs/common": "^10.3.9",
"@nestjs/core": "^10.3.9",
Thanks!