简体   繁体   English

Nestjs 无法解析 XModel 的依赖关系

[英]Nestjs can't resolve dependencies of XModel

I have been working on this app for like 3 months which is near completion.我已经在这个应用程序上工作了 3 个月,接近完成。 But since yesterday I have been unable to solve this problem.但是从昨天开始,我一直无法解决这个问题。 I want to use activityTypeService in activityLogService and I have been getting this wired error.我想在activityLogService 中使用activityTypeService,但我一直收到这个有线错误。 I have already exported activityTypeservice in its module.我已经在其模块中导出了 activityTypeservice。 see below见下文

below is ActivityTypeModule, I export ActivityTypeService so it can available in ActivityLogService下面是 ActivityTypeModule,我导出 ActivityTypeService 以便它可以在 ActivityLogService 中使用

@Module({
  imports: [MongooseModule.forFeature([{ name: 'ActivityType', schema: ActivityTypeSchema },])],
  providers: [ActivityTypeService,],
  controllers: [ActivityTypeController],
  exports: [ActivityTypeService,]
})
export class ActivityTypeModule { }

The code below is activityLog module and ActivityTypeModule is imported下面的代码是activityLog模块并导入了ActivityTypeModule

@Module({
  imports: [MongooseModule.forFeature([{ name: 'ActivityLog', schema: ActivityLogSchema }]), ActivityTypeModule],
  providers: [ActivityLogService, ActivityTypeModule],
  controllers: [ActivityLogController],
  exports: [MongooseModule,]
})
export class ActivityLogModule { }

so I use it the activityLogService as shown below所以我使用它的activityLogService,如下所示

@Injectable()
export class ActivityLogService {
    constructor(@InjectModel('ActivityLog') private activitylogModel: Model<ActivityLog>,
        private activityTypeService: ActivityTypeService
    ) { }

    async activitylog(activityuser: string, activitytype: string, activitydetails: string, activitydate: Date) {
        const activitiesLog = {
            activityuser: activityuser,
            activitytype: activitytype,
            activitydetails: activitydetails,
            activitydate: activitydate
        }
        const activity = new this.activitylogModel(activitiesLog);
        console.log(activity);
        await activity.save()
    }
}

But I am still getting this wired error which I dont understand但我仍然收到这个我不明白的有线错误

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

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

From your error, somewhere you have ActivityTypeService in an imports array somewhere, which shouldn't be happening.根据您的错误,您在某个地方的imports数组中有ActivityTypeService ,这不应该发生。 Along with that, I can see you have ActivityTypeModule in a providers array, which is also not supported, though Typescript doesn't have a good way to show errors about that, so you aren't seeing any errors.除此之外,我可以看到您在providers数组中有ActivityTypeModule ,虽然 Typescript 没有显示错误的好方法,但您没有看到任何错误。

In general, as Nest error like that is in the form of一般来说,像这样的 Nest 错误的形式是

Nest can't resolve dependencies of the <Provider> (?). Please make sure that the argument <injected_valued> at index [<index>] is available in the <module> context.

<Provider> and <module> should never be the same value, and if they are, it's a good indication that you have a provider in an imports array. <Provider><module>不应该是相同的值,如果它们是,这很好地表明您在导入数组中有一个提供程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM