Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NestJS - Can't resolve queue?

Tags:

nestjs

I am following doc to start to use queue. I installed @nestjs/bull, bull, @types/bull dependencies. And here is my app.module.ts:

@Module({
    imports: [
        ConfigModule.forRoot({
            load: [configuration],
        }),
        BullModule.registerQueue({
            name: 'create_checkin',
            redis: {
                host: 'localhost',
                port: 6379,
            },
        }),
        EventModule,
    ],
})
export class AppModule {}

I imported BullModule in root module. And here is my event.service.ts:

@Injectable()
export class EventService {

    constructor(
        @InjectQueue('create_checkin') private readonly createCheckinQueue: Queue,
    ) {
    }
}

And when I start server, I got the following error message:

Nest can't resolve dependencies of the EventService
Please make sure that the argument BullQueue_create_checkin at index [0] is available in the EventModule context.

I don't know which step I did wrong. Someone can help me?

like image 343
user11762401 Avatar asked Jun 08 '26 00:06

user11762401


1 Answers

Had a similar problem, in my case it was enough to add the BullModule to the exports array in order to successfully run the whole project. Like this:

@Module({
  imports: [
    BullModule.registerQueue({ ... }),
    ...
  ],
  ...
  exports: [
    BullModule,  // <— this is important!
    ...
  ]
})

Then in my service I've been able to inject the queue:

@InjectQueue('print') private queue: Queue<PrintJob>
like image 119
Hello Human Avatar answered Jun 10 '26 14:06

Hello Human



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!