When I run the Nestjs server, I get the following error. I am using the NestJS BullModule.
Error: Nest can’t resolve dependencies of the
BullExplorer (?, DiscoveryService, BullMetadataAccessor, MetadataScanner)
Please make sure that the argument ModuleRef at index [0] is available in the BullModule context.
Potential solutions:
- If ModuleRef is a provider, is it part of the current BullModule?
- If ModuleRef is exported from a separate @Module, is that module imported within BullModule?
@Module({ imports: [ /* the Module containing ModuleRef */ ] })
Here is the Bull module configuration:
BullModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => {
const redisConfig = configService.get<RedisConfig>("redis");
return {
redis: {
host: redisConfig.host,
port: redisConfig.port,
},
defaultJobOptions: {
timeout: 30000,
removeOnComplete: true,
removeOnFail: true,
attempts: 3,
},
};
},
inject: [ConfigService],
}),
BullModule.registerQueue({
name: MAIL_QUEUE,
}),
2
Answers
The problem has to do with how yarn workspaces work... my monorepo did not work properly when the Nestjs Bull module was installed in it using yarn v. 1.18.0.
My Original Answer: Upgraded the yarn from 1.18.0 to 1.22.15
Edited Answer: After deleting the node_modules folders, and doing the fresh install using yarn 1.22.15.. I bumped into the same error message again.
Finally, I decided to use pnpm workspaces and the new setup worked like a charm.
Hope someone may find it useful.
Turns out the problem is known in NestJS community. There is a whole thread on their discord here and PR to the documentation, mentioning how to fix the problem, waiting for merging here. Long story short, if you’re working in monorepo setup with yarn workspaces, you don’t want to hoist your
@nestjs
dependencies. Configure this in your root levelpackage.json
like this: