nest-queue icon indicating copy to clipboard operation
nest-queue copied to clipboard

registerAsync is not passing imports array

Open cojack opened this issue 5 years ago • 3 comments

As in topic, because of this I'm not able to create an app:

        QueueModule.registerAsync({
            isGlobal: true,
            useClass: AppQueueService,
            imports: []
        }),

It returns me an error:

[Nest] 26166   - 01/12/2021, 1:25:20 PM   [ExceptionHandler] Nest can't resolve dependencies of the __QUEUE_OPTIONS__ (?). Please make sure that the argument AppQueueService at index [0] is available in the QueueModule context.

Potential solutions:                                                                                                                                                                                                                                                                                                       
- If AppQueueService is a provider, is it part of the current QueueModule?                                                                                                                                                                                                                                                 
- If AppQueueService is exported from a separate @Module, is that module imported within QueueModule?                                                                                                                                                                                                                      
  @Module({
    imports: [ /* the Module containing AppQueueService */ ]
  })
 +0ms

Where class looks like this:

@Injectable()
export class AppQueueService implements QueueAsyncOptionsFactory {
    constructor(
        @Inject(awsConfig.KEY)
        private readonly configAws: ConfigType<typeof awsConfig>
    ) {}
}

cojack avatar Jan 12 '21 12:01 cojack

Hi @cojack, I will the check the useClass issue, shouldn't be happening. But for the time being can you try using the imports with useFactory setting and let us know if it is working fine.

I will be debugging and releasing an updated version of the package soon with the bug fix.

vinayak25 avatar Jan 12 '21 13:01 vinayak25

@vinayak25 yes, useFactory is working

        QueueModule.registerAsync({
            isGlobal: true,
            useFactory: (configAws) => (new AppQueueService(configAws)).createQueueOptions(),
            inject: [awsConfig.KEY],
            imports: []
        }),

cojack avatar Jan 12 '21 14:01 cojack

Thanks for the update @cojack, request you to please go forward with the useFactory configuration only. I will be releasing a new version with the bug fix soon or please feel free to raise a PR!

vinayak25 avatar Jan 13 '21 09:01 vinayak25