I got error on my nestjs app. I cant figure out whats wring with my code. I The codes is something like this
AppModule
import { Module } from '@nestjs/mon';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AdminModule } from './ponents/admin.modules';
@Module({
imports: [
AdminModule,
TypeOrmModule.forRoot({
type: 'postgres',
host: process.env.DATABASE_HOST,
username: process.env.DATABASE_USERNAME,
password: process.env.DATABASE_PASSWORD,
database: process.env.DATABASE_NAME,
port: parseInt(process.env.DATABASE_PORT),
}),
],
})
export class AppModule {}
AdminModule
import { Module } from '@nestjs/mon';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Admin } from './admin.entity';
import { AdminRepository } from './admin.repository';
@Module({
imports: [TypeOrmModule.forFeature([Admin])],
providers: [AdminRepository],
})
export class AdminModule {}
AdminRepository
import { Injectable } from '@nestjs/mon';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { RepositoryBase } from '../../mon/base/repository.base';
import { Admin } from './admin.entity';
@Injectable()
export class AdminRepository extends RepositoryBase<Admin> {
constructor(@InjectRepository(Admin) private readonly repo: Repository<Admin>) {
super(repo);
}
And what i get is error like this
Error: Nest can't resolve dependencies of the AdminRepository (?). Please make sure that the argument AdminRepository at index [0] is available in the AdminModule context.
Potential solutions: - If AdminRepository is a provider, is it part of the current AdminModule? - If AdminRepository is exported from a separate @Module, is that module imported within AdminModule?
I got error on my nestjs app. I cant figure out whats wring with my code. I The codes is something like this
AppModule
import { Module } from '@nestjs/mon';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AdminModule } from './ponents/admin.modules';
@Module({
imports: [
AdminModule,
TypeOrmModule.forRoot({
type: 'postgres',
host: process.env.DATABASE_HOST,
username: process.env.DATABASE_USERNAME,
password: process.env.DATABASE_PASSWORD,
database: process.env.DATABASE_NAME,
port: parseInt(process.env.DATABASE_PORT),
}),
],
})
export class AppModule {}
AdminModule
import { Module } from '@nestjs/mon';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Admin } from './admin.entity';
import { AdminRepository } from './admin.repository';
@Module({
imports: [TypeOrmModule.forFeature([Admin])],
providers: [AdminRepository],
})
export class AdminModule {}
AdminRepository
import { Injectable } from '@nestjs/mon';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { RepositoryBase } from '../../mon/base/repository.base';
import { Admin } from './admin.entity';
@Injectable()
export class AdminRepository extends RepositoryBase<Admin> {
constructor(@InjectRepository(Admin) private readonly repo: Repository<Admin>) {
super(repo);
}
And what i get is error like this
Share Improve this question asked Feb 19, 2020 at 23:59 sundaemsundaem 2031 gold badge3 silver badges5 bronze badges 1Error: Nest can't resolve dependencies of the AdminRepository (?). Please make sure that the argument AdminRepository at index [0] is available in the AdminModule context.
Potential solutions: - If AdminRepository is a provider, is it part of the current AdminModule? - If AdminRepository is exported from a separate @Module, is that module imported within AdminModule?
- Hi! Can you provide a repository.base file? – Yaro Commented Aug 7, 2022 at 8:00
1 Answer
Reset to default 15I think the problem is the name you are giving to the provider: AdminRepository
. Quite likely, internally TypeOrm
is using that name to create a repository for the Admin
entity and hence the name clash.
If you rename your provider class to anything else, (e.g. AdminRepo
or AdminService
), the error should go away.
Or another thing to do would be to rename the entity class from Admin
to something else.
What you want to avoid is creating a class with ${EntityClassName}Repository