Peter94
Peter94

Reputation: 33

Nest can't resolve dependencies of RabbitMQService service

I am building a nestjs app where I want to create a rabbitmq

@Module({
imports: [
    ClientsModule.register([
        {
            name: 'rabbitmq',
            transport: Transport.RMQ,
            options: {
                urls: [
                    'amqp://guest:guest@rabbitmq',
                ],
                queue: 'my_queue',
            },
        },
    ]),
],
controllers: [],
providers: [RabbitMQService],
exports: [RabbitMQService],

})

And service:

@Injectable()

export class RabbitMQService { constructor( @Inject('rabbitmq') private client: ClientProxy ) {} }

The error I am getting is: Nest can't resolve dependencies of the RabbitMQService (?). Please make sure that the argument rabbitmq at index [0] is available in the RabbitMQService context. As much I am aware, this should work, but nope. Could anyone help?

Upvotes: 1

Views: 1404

Answers (1)

Jay McDoniel
Jay McDoniel

Reputation: 70131

From the error, it looks like somewhere in your application you have RabbitMQService in an imports array where @Module() classes are supposed to go. Make sure that you keep providers and other @Injectables() to the providers array and keep @Module() and other DynamicModules to the imports array. Common error docs

Upvotes: 3

Related Questions