[英]NestJS Nest can't resolve dependencies of the RolesService (+, +, ?)
[英]NestJS can't resolve dependencies of the AuthServices
在遇到JWT_MODULE_OPTION的第一個問題后,回到我認為自己已解決的老問題。 原來,當我“解決”舊問題時,請使用JWT創建新問題。
所以再次無法編譯:
Nest無法解析AuthService(?,RoleRepository,JwtService)的依賴項。 請確保在AppModule上下文中索引[0]處的參數可用。 + 25ms的
真的很奇怪,因為這種方式可以在我的另一個項目中工作,並且無法理解我錯了。 這是auth.service.ts :
@Injectable()
export class AuthService {
constructor(
@InjectRepository(User) private readonly userRepo: Repository<User>,
@InjectRepository(Role) private readonly rolesRepo: Repository<Role>,
private readonly jwtService: JwtService,
) { }
它獲得角色和jwtService
但問題出在User
,路徑正確。 這是app.module.ts :
@Module({
imports: [
TypeOrmModule.forRootAsync({
imports: [ConfigModule, AuthModule],
inject: [ConfigService],
useFactory: async (configService: ConfigService) => ({
type: configService.dbType as any,
host: configService.dbHost,
port: configService.dbPort,
username: configService.dbUsername,
password: configService.dbPassword,
database: configService.dbName,
entities: ['./src/data/entities/*.ts'],
}),
}),
],
controllers: [AppController, AuthController],
providers: [AuthService],
})
export class AppModule { }
控制器和提供者具有相同的編譯錯誤,並且無法理解錯誤所在...
您可能缺少TypeOrmModule.forFeature([User])
導入。 通常,所有實體都將導入到專用功能模塊中。 如果你只有一個模塊(即AppModule
),你需要把forFeature
進口有除了forRoot
進口。
@Module({
imports: [
TypeOrmModule.forRootAsync({...}),
TypeOrmModule.forFeature([User, Role]),
],
全局問題是我嘗試兩次添加AuthService和AuthController。 所以我將它們從app.module.ts中刪除,然后從auth.module.ts中導出AuthService :
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.