【发布时间】:2021-06-22 12:36:29
【问题描述】:
我是 NestJs 环境的新手,我目前面临这个错误,并在 github 上寻找问题解决方案,但无法帮助我得到错误的结果。
[Nest] 22140 - 21/06/2021 à 14:51:40 [ExceptionHandler] Nest can't resolve dependencies of the UsersRepository (?). Please make sure that the argument Connection at index [0] is available in the TypeOrmModule context.
Potential solutions:
- If Connection is a provider, is it part of the current TypeOrmModule?
- If Connection is exported from a separate @Module, is that module imported within TypeOrmModule?
@Module({
imports: [ /* the Module containing Connection */ ]
})
我已经在我的 auth.module.ts 上声明了它
import { Module } from '@nestjs/common';
import { AuthService } from './auth.service';
import { AuthController } from './auth.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UsersRepository } from './users.repository';
@Module({
imports: [TypeOrmModule.forFeature([UsersRepository])],
providers: [AuthService],
controllers: [AuthController],
})
export class AuthModule {}
并在我的服务文件中使用它。
import { Injectable } from '@nestjs/common';
import { UsersRepository } from './users.repository';
import { InjectRepository } from '@nestjs/typeorm';
import { AuthCredentialsDto } from './dto/auth-credentials.dto';
@Injectable()
export class AuthService {
constructor (
@InjectRepository(UsersRepository)
private usersRepository: UsersRepository,
) {}
async signUp(authCredentialsDto: AuthCredentialsDto): Promise<void> {
return this.usersRepository.createUser(authCredentialsDto);
}
}
【问题讨论】:
-
您的
AppModule中有TypeOrmModule.forRoot/Async(),对吗?你是如何运行产生错误的代码的?
标签: typescript nestjs