nest: [ExceptionHandler] Nest can't resolve dependencies of the FileService (?, +). Please verify whether [0] argument is available in the current context.

I’m submitting a…


[ ] Regression 
[x ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Trying to use my fileRepository: Repository<File> in my FileService, but I get the following error: [ExceptionHandler] Nest can't resolve dependencies of the FileService (?, +). Please verify whether [0] argument is available in the current context.

Expected behavior

It should work

Minimal reproduction of the problem with instructions

I had no problem on other modules, I have no idea why I get this error on this one.

file.module.ts

@Module({
    imports: [TypeOrmModule.forFeature([File]), GlobalModule],
    components: [FileService, GlobalService],
    controllers: [FileController],
})
export class FileModule {}

file.service.ts

constructor(@InjectRepository(File)
                private readonly fileRepository: Repository<File>,
                private globalService: GlobalService) {

    }

app.module.ts

@Module({
  imports: [TypeOrmModule.forRoot({
      type: 'mysql',
      host: 'localhost',
      port: 3306,
      username: 'root',
      password: '',
      database: 'thordetsv2',
      entities: [__dirname + '/../**/*.entity{.ts,.js}'],
      synchronize: true,
  }),
      BugModule,
      VersionModule,
      FileModule
  ],
  controllers: [AppController],
  components: [],
})

What is the motivation / use case for changing the behavior?

bugfix

Environment


Nest version: 4.5.10

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 17 (3 by maintainers)

Most upvoted comments

exports: [FileService] in FileModule, import FileModule in BugModule and remove FileService from components in BugModule

if I do it like this, I am able to npm start the project without any issues

@Module({
    imports: [TypeOrmModule.forFeature([File]), GlobalModule],
    components: [FileService],
    controllers: [FileController],
    exports: [FileService]
})
export class FileModule {}
@Module({
    imports: [TypeOrmModule.forFeature([Bug]), GlobalModule, FileModule],
    components: [BugService, GlobalService],
    controllers: [BugController],
})
export class BugModule {}

Do you also export the GlobalService within the GlobalModule as you are importing the GlobalService in your FileService? I think the FileModule itself seems to be correct. I have faced such an issue myself 😃 And I don’t think you need to import the GlobalService into your FileModule too.

@Module({
  imports: [],
  components: [],
  controllers: [],
  exports: [GlobalService],
})

@lo78cn That’s the issue, I had to export FileService and I didn’t. Now everything works great.

Thanks!