'Nest can't resolve dependencies of the TypeOrmCoreModule
src/contact/contact.module.ts
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ContactController } from './contact.controller';
import { Contact } from './contact.entity';
import { ContactRepository } from './contact.repo';
import { ContactService } from './contact.service';
@Module({
imports: [
TypeOrmModule.forFeature([
Contact,
]),
],
controllers: [ContactController],
providers: [ContactService, ContactRepository],
})
export class ContactModule {}
src/app.module.ts
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { getMetadataArgsStorage } from 'typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ContactModule } from './contact/contact.module';
@Module({
imports: [
TypeOrmModule.forRoot({
type: 'sqlite',
database: 'db',
entities: getMetadataArgsStorage().tables.map(tbl => tbl.target),
synchronize: true,
}),
ContactModule
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
npm new start:dev
Give this kind of error where I try to find possibly every solution on the internet but what mistake I'm doing I don't know, I got an error like.
nest -v (8.1.6)
ERROR [ExceptionHandler] Nest can't resolve dependencies of the TypeOrmCoreModule (TypeOrmModuleOptions, ?). Please make sure that the argument ModuleRef at index [1] is available in the TypeOrmCoreModule context.
Potential solutions:
- If ModuleRef is a provider, is it part of the current TypeOrmCoreModule?
- If ModuleRef is exported from a separate @Module, is that module imported within TypeOrmCoreModule?
@Module({
imports: [ /* the Module containing ModuleRef */ ]
})
Solution 1:[1]
I was having this problem because of a bad installation of typeorm.
Works for me:
1- Delete node_module
2- Run npm i
3- Run npm install --save @nestjs/typeorm typeorm mysql2 again im my project.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alyf Mendonça |
