Nest 无法解析 UserService 的依赖关系(?)。请确保索引 [0] 处的参数在当前上下文中可用

问题描述 投票:0回答:1

遇到一些问题,di/circular-references我确信我做错了,我只是看不到它。

任何帮助将不胜感激

用户.module.ts

import { Module } from '@nestjs/common';
import { UserService } from './user.service';
import { UserController } from './user.controller';
import { PrismaService } from 'src/prisma/prisma.service';

@Module({
  controllers: [UserController],
  providers: [UserService, PrismaService],
})
export class UserModule {}

auth.module.ts

import { Module } from '@nestjs/common';
import { AuthService } from './auth.service';
import { AuthController } from './auth.controller';
import { UserService } from 'src/user/user.service';
import { PrismaService } from 'src/prisma/prisma.service';

@Module({
  controllers: [AuthController],
  providers: [AuthService, UserService, PrismaService],
})
export class AuthModule {}

app.module.ts

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { PrismaService } from './prisma/prisma.service';
import { AuthModule } from './auth/auth.module';
import { UserModule } from './user/user.module';

@Module({
  imports: [AuthModule, UserModule],
  controllers: [AppController],
  providers: [AppService, PrismaService],
})
export class AppModule {}
ERROR [ExceptionHandler] Nest can't resolve dependencies of the UserService (?). Please make sure that the argument Function at index [0] is available in the AuthModule context.

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

Error: Nest can't resolve dependencies of the UserService (?). Please make sure that the argument Function at index [0] is available in the AuthModule context.

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

最初有“Nest无法解析

UserService
的依赖关系。然后我完全删除了
UserModule
并只使用了
AuthModule
,一切正常。你能告诉我我错在哪里吗? 预先感谢。

module nestjs nest
1个回答
0
投票

存在循环依赖。

constructor(@Inject(forwardRef(() => UserService)) private readonly userService: UserService) {}

将此行添加到您的 auth 服务中。 (Auth.service.ts)

并尝试分享 AuthServices 的代码。

© www.soinside.com 2019 - 2024. All rights reserved.