![](/img/trans.png)
[英]Nest can't resolve dependencies of the RegisterService (?).Please make sure that the argument at index [0] is available in the RegisterModule context
[英]Nest can't resolve dependencies of the …Please make sure that the argument .. at index [0] is available in the
我有:
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();
}
}
我得到了這個奇怪的錯誤:
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
是:
import { Module } from '@nestjs/common';
import { ConversationsController } from './conversations.controller';
import { ConversationsService } from './conversations.service';
@Module({
controllers: [ConversationsController],
providers: [ConversationsService]
})
export class ConversationsModule {}
不確定ConversationRepository
指的是什么。
您需要將SequelizeModule.forFeature()
添加到您的ConversationModule
的imports
數組中,以告訴 Nest 在此模塊的上下文中,我可以訪問ConversationRepository
。 該術語是從 TypeORM 借用的,與 TypeO 一樣,您有實體和存儲庫,但是對於 Sequelize,您有模型和表,但總體思路是相同的。 你的ConverstationModule
應該看起來像這樣:
@Module({
imports: [SequelizeModule.forFeature([Conversation])],
providers: [ConversationService],
controllers: [ConversationController]
})
export class ConversationModule {}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.