简体   繁体   English

Nest 无法解析...的依赖关系...请确保索引 [0] 处的参数 .. 在

[英]Nest can't resolve dependencies of the …Please make sure that the argument .. at index [0] is available in the

I have:我有:

import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/sequelize';
import { Conversation } from './conversation.model'
import { FindConversationsDto } from '../dto/conversations.find'

@Injectable()
export class ConversationsService {
    constructor(
        @InjectModel(Conversation)
        private conversationModel: typeof Conversation
    ) { }

    async findConversations(queryParams: FindConversationsDto): Promise<Conversation[]> {
        return new Promise((resolve) => [])
        // return await this.conversationModel.findAll();


    }
}

And I get this weird error:我得到了这个奇怪的错误:

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

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

ConversationModule is: ConversationModule是:

import { Module } from '@nestjs/common';
import { ConversationsController } from './conversations.controller';
import { ConversationsService } from './conversations.service';

@Module({
  controllers: [ConversationsController],
  providers: [ConversationsService]
})
export class ConversationsModule {}

Not sure what ConversationRepository is referring to.不确定ConversationRepository指的是什么。

You need to add in the SequelizeModule.forFeature() to your ConversationModule 's imports array, to tell Nest that in the context of this module, I have access to the ConversationRepository .您需要将SequelizeModule.forFeature()添加到您的ConversationModuleimports数组中,以告诉 Nest 在此模块的上下文中,我可以访问ConversationRepository The terminology is borrowed from TypeORM, as with TypeO you have Entities and Repositories, but whereas with Sequelize you have Models and Tables, but the ideas are the same overall.该术语是从 TypeORM 借用的,与 TypeO 一样,您有实体和存储库,但是对于 Sequelize,您有模型和表,但总体思路是相同的。 Your ConverstationModule should probably look something like this:你的ConverstationModule应该看起来像这样:

@Module({
  imports: [SequelizeModule.forFeature([Conversation])],
  providers: [ConversationService],
  controllers: [ConversationController]
})
export class ConversationModule {}

暂无
暂无

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

相关问题 Nest 无法解析 RegisterService (?) 的依赖关系。请确保索引 [0] 处的参数在 RegisterModule 上下文中可用 - Nest can't resolve dependencies of the RegisterService (?).Please make sure that the argument at index [0] is available in the RegisterModule context Nest 无法解析 JobsService (?) 的依赖关系。 请确保索引 [0] 处的参数 JobModel 在 AppModule 上下文中可用 - Nest can't resolve dependencies of the JobsService (?). Please make sure that the argument JobModel at index [0] is available in the AppModule context 无法解析 ChannelService 的依赖关系(?确保索引 [0] 处的参数 ChannelRepository 在 ChannelService 上下文中可用 - Can't resolve dependencies of the ChannelService (? make sure the argument ChannelRepository at index [0] is available in the ChannelService context Nest无法解析VendorsService(?)的依赖关系。 请验证[0]参数在当前上下文中是否可用 - Nest can't resolve dependencies of the VendorsService (?). Please verify whether [0] argument is available in thecurrent context Nest 无法解决 - Nest can't resolve dependencies of the Nest无法解析依赖项 - Nest can't resolve dependencies Nest 无法解析 USERRepository 的依赖项 - Nest can't resolve dependencies of the USERRepository NestJS Nest无法解析RolesService的依赖关系(+,+ ,?) - NestJS Nest can't resolve dependencies of the RolesService (+, +, ?) Nest 无法解析 AuthService (AuthRepository, ?) 的依赖项 - Nest can't resolve dependencies of the AuthService (AuthRepository, ?) Nest 无法解析 UserModel 的依赖项(?) - Nest can't resolve dependencies of the UserModel (?)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM