Nestjs 无法解决我的依赖关系,即使它在模块上下文中可用

Nestjs can't resolve my dependency even though it's available in Module context

我收到这样的错误:

Error: Nest can't resolve dependencies of the CreateGroupTask (TaskQueueService, GroupsService, ?, GroupNotificationsService, GroupRepository, Logger). Please make sure that the argument dependency at index [2] is available in the TasksModule context.

CreateGroupTasks 服务看起来像这样:

import { Logger } from 'nestjs-pino';
import { GroupNotificationsService } from '../bll/group/group-notifications.service';
import { Injectable, OnApplicationBootstrap } from '@nestjs/common';
import { GroupsService } from '../bll/group/groups.service';
import { PotentialGroupsService } from '../bll/potential-groups/potential-groups.service';
import { GroupRepository } from '../dal/user-group/group.repository';
import { TaskQueueService } from '../task-queue/task-queue.service';

export const CREATE_GROUP_TASK_NAME = 'create-group';
const CREATE_GROUP_TASK_DOMAIN = 'create-group-task';
@Injectable()
export class CreateGroupTask implements OnApplicationBootstrap {
  constructor(
    private readonly taskQueueService: TaskQueueService,
    private readonly groupsService: GroupsService,
    private readonly potentialGroupService: PotentialGroupsService,
    private readonly groupNotificationsService: GroupNotificationsService,
    private readonly groupsRepository: GroupRepository,
    private readonly logger: Logger,
  ) {}

  onApplicationBootstrap() {
    this.taskQueueService.registerTaskHandler(
      CREATE_GROUP_TASK_NAME,
      this.handle.bind(this),
    );
  }

  async handle([potentialGroupId]: [number]) { //handler code }
}

从 BusinessLogicModule 模块导出的 PotentialGroupsService 以及 GroupsService 和 GroupNotificationsService:

import { Module } from '@nestjs/common';
import { SendAuthLinkTask } from './send-auth-link.task';
import { CallReminderTask } from './call-reminder-task';
import { TaskQueueModule } from '../task-queue/task-queue.module';
import { RepositoryModule } from '../dal/repository.module';
import { CommunicationsgModule } from '../communication/communications.module';
import { BusinessLogicModule } from '../bll/business-logic.module';
import { SendStatsTask } from './send-stats.task';
import { WorkoutNotificationTask } from './workout-notification.task';
import { SayWelcomeTask } from './say-welcome.task';
import { CreateGroupTask } from './create-group.task';
import { GroupStartsReminderTask } from './group-starts-reminder.task';

@Module({
  imports: [
    TaskQueueModule,
    CommunicationsgModule,
    RepositoryModule,
    BusinessLogicModule,
  ],
  providers: [
    SendAuthLinkTask,
    CallReminderTask,
    SendStatsTask,
    WorkoutNotificationTask,
    SayWelcomeTask,
    CreateGroupTask,
    GroupStartsReminderTask,
  ],
})
export class TasksModule {}

以及从 BusinessLogicModule 导出的所有这些服务:

import { Module } from '@nestjs/common';
import { CommunicationsgModule } from '../communication/communications.module';
import { RepositoryModule } from '../dal/repository.module';
import { AuthService } from './auth-logic/auth.service';
import { SessionService } from './auth-logic/session.service';
import { GroupNotificationsService } from './group/group-notifications.service';
import { UserService } from './user/user.service';
import { MessageService } from './conversation/message.service';
import { ConversationService } from './conversation/conversation.service';
import { GroupsService } from './group/groups.service';
import { StatsService } from './statistics/workouts-stats';
import { InvitationsService } from './invitations/invitations.service';
import { TaskValidator } from './group/notification-task-validator.service';
import { PotentialGroupsService } from './potential-groups/potential-groups.service';
import { PotentialGroupCheckerCron } from './potential-groups/potential-groups-checker.cron';

@Module({
  imports: [CommunicationsgModule, RepositoryModule],
  providers: [
    AuthService,
    SessionService,
    GroupNotificationsService,
    UserService,
    MessageService,
    ConversationService,
    GroupsService,
    StatsService,
    InvitationsService,
    TaskValidator,
    PotentialGroupsService,
    PotentialGroupCheckerCron,
  ],
  exports: [
    AuthService,
    SessionService,
    GroupNotificationsService,
    UserService,
    MessageService,
    ConversationService,
    GroupsService,
    StatsService,
    InvitationsService,
    TaskValidator,
    PotentialGroupsService,
  ],
})
export class BusinessLogicModule {}

我做错了什么?为什么 nest 无法解析 PotentialGroupService?

来自错误:

Error: Nest can't resolve dependencies of the CreateGroupTask (TaskQueueService, GroupsService, ?, GroupNotificationsService, GroupRepository, Logger). Please make sure that the argument dependency at index [2] is available in the TasksModule context.

Nest 无法解析参数 dependency。通常发生这种情况时会出现无法解析的循环文件导入,这意味着依赖项以 undefined 的形式出现,因此 Nest 为依赖项提供了一个通用名称。检查您的文件导入(包括桶文件)并确保您没有意外创建循环导入。

无法解析 PotentialGroups。

确保在 BusinessLogicModule 中导入了 PotentialGroupsModule。 还要确保 PotentialGroupsService 是从 PotentialGroupsModule

导出的