Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nest can't resolve dependencies of the TELEGRAM_MODULE_OPTIONS #332

Open
sergeycherepanov opened this issue Apr 23, 2022 · 7 comments
Open

Comments

@sergeycherepanov
Copy link

sergeycherepanov commented Apr 23, 2022

Hi, when I follow steps from the readme I got following error:

ERROR [ExceptionHandler] Nest can't resolve dependencies of the TELEGRAM_MODULE_OPTIONS (?). 
Please make sure that the argument ConfigService at index [0] is available in the TelegramModule context.
@trgkyle
Copy link

trgkyle commented Jul 1, 2022

I got the same did any one solve this problem ?

@embyth
Copy link

embyth commented Sep 10, 2022

To use async module import like this:

TelegramModule.forRootAsync({
  useFactory: async (configService: ConfigService) => ({
    botKey: configService.get('BOT_TOKEN'),
  }),
  inject: [ConfigService],
}),

You need to make your config service globally visible, so in AppModule just add isGlobal: true

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
  ],
  providers: [AppService],
})
export class AppModule {}

@anvu69
Copy link

anvu69 commented Oct 5, 2022

I tried this way and no more error:

@Injectable()
export class HookTelegramService {
  private readonly telegram: TelegramService

  async sendMessage(sendMessageParam: TelegramSendMessageParams): Promise<TelegramMessage> {
    const result = await this.telegram.sendMessage(sendMessageParam).toPromise()

    return result
  }
}

Move private readonly telegram: TelegramService outside constructor but this.telegram return undefined

@anvu69
Copy link

anvu69 commented Oct 5, 2022

Hi, when I follow steps from the readme I got following error:

ERROR [ExceptionHandler] Nest can't resolve dependencies of the TELEGRAM_MODULE_OPTIONS (?). 
Please make sure that the argument ConfigService at index [0] is available in the TelegramModule context.

I tried to use OnModuleInit and run perfect.

export class HookTelegramService implements OnModuleInit {
  private readonly logger = new Logger(HookTelegramService.name)

  private telegram: TelegramService

  constructor(private moduleRef: ModuleRef) {}

  onModuleInit() {
    this.telegram = this.moduleRef.get(TelegramService, { strict: false })
  }

  async sendMessage(sendMessageParam: TelegramSendMessageParams): Promise<TelegramMessage> {
    const result = await this.telegram.sendMessage(sendMessageParam).toPromise()

    return result
  }
}

@julihermes
Copy link

you have to inject the service.

constructor(private readonly telegram: TelegramService) {}

@antonygiomarx
Copy link

I removed the TelegramService from exports and providers and the error disappeared.

@fromage9747
Copy link

you need to change your async import to include the ConfigModule:

TelegramModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
botKey: configService.get('TELEGRAM_API_Key')
}),
inject: [ConfigService]
}),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants