遇到一些问题,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
,一切正常。你能告诉我我错在哪里吗?
预先感谢。
存在循环依赖。
constructor(@Inject(forwardRef(() => UserService)) private readonly userService: UserService) {}
将此行添加到您的 auth 服务中。 (Auth.service.ts)
并尝试分享 AuthServices 的代码。