question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

8reactions
lo78cncommented, Feb 25, 2018

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 {}
6reactions
lo78cncommented, Feb 19, 2018

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],
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Nest can't resolve dependencies of the (?). Please make sure ...
Please make sure that the argument at index [0] is available in the RootTestModule context. This project is using Mongoose for connecting to ......
Read more >
nest can't resolve dependencies of the - You.com
Nest can't resolve dependencies of the PhotoService (?). Please verify whether [0] argument is available in the current context. I'm following the database ......
Read more >
NestJS: Resolving Dependency Injection - Tevpro
Nest can't resolve dependencies of the AuthController (?). Please make sure that the argument dependency at index [0] is available in the AuthModule...
Read more >
Nest can't resolve dependencies of the UsersService ... - Reddit
Please make sure that the argument User at index [0] is available in the RootTestModule context. Potential solutions: - If User is a...
Read more >
How to avoid circular dependencies in NestJS - LogRocket Blog
NestJS code will not even compile if there is an unresolved circular dependency. In this article, we will be learning about circular ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found