簡體   English   中英

NestJS 循環依賴問題

[英]NestJS Circular Dependency Issue

我在使用 NestJS 模塊時遇到了一個奇怪的問題,錯誤是要求我將相同的模塊導入其中。 我在下面附上了一個錯誤。

error

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

user.service.ts

@Injectable()
export class UserService {
  constructor(
    @InjectRepository(User)
    private readonly userRepository: Repository<User>
  ) {}
}

user.module.ts

@Module({
  imports: [
    TypeOrmModule.forFeature([User]),
  ],
  providers: [UserService],
  controllers: [UserController],
})
export class UserModule {}

根據錯誤,您在某處將UserService添加到imports數組。 Providers永遠不屬於imports數組,您應該導入UserModule ,它應該在providersexports數組中包含UserService

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM