Skip to content

Error: Nest can't resolve dependencies of the AlertProvider (?). #33

Open
@probil

Description

@probil

I'm new to nest.js. I don't know why Nest cant resolve dependencies. And there is nothing in README. I had found something similar in closed issues but it didn't help. Here is an error

Error: Nest can't resolve dependencies of the AlertProvider (?). Please make sure that the argument at index [0] is available in the AlertModule context.

Here is my files (cleaned up a little bit):

// app/app.module.ts
import { Module } from '@nestjs/common';

@Module({
  imports: [
    ConfigModule.load(
      path.resolve(process.cwd(), 'config', '**/!(*.d).{ts,js}'),
    ),
    AmqpModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (config: ConfigService) => config.get('amqp'),
    }),
    //...
})
export class AppModule implements NestModule
// config/amqp.ts
export default {
  name: 'default',
  hostname: process.env.AMQP_HOST || 'mq-service',
  port: process.env.AMQP_PORT || 5672,
  username: process.env.USERNAME || 'guest',
  password: process.env.PASSWORD || 'guest',
};
// alert/alert.module.ts
import { Module } from '@nestjs/common';
import { AmqpModule } from 'nestjs-amqp';
import { AlertService } from './alert.service';
import { AlertProvider } from './alert.provider';

@Module({
  imports: [
    AmqpModule.forFeature(),  // The error also occurs without this line
  ],
  providers: [
    AlertService,
    AlertProvider,
  ],
})
export class AlertModule {}
// alert/alert.provider.ts
import { InjectAmqpConnection } from 'nestjs-amqp';

const QUEUE = 'alerts';

export class AlertProvider {
  constructor(
    @InjectAmqpConnection('default') private readonly amqp,
  ) {
    this.setupListeners();
  }

  async setupListeners() {
    const channel = await this.amqp.createChannel();
    await channel.assertQueue(QUEUE);
    channel.consume(QUEUE, (msg) => {
      if (msg === null) {
        return;
      }
      console.log(msg.content.toString());
    });
  }
}

Maybe you can suggest me something.
I use nest@v6 and latest version of nestjs-amqp

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions