Nest.js can't resolve dependencies of the external library's Reflector dependency

25 Views Asked by At

my colleagues and I have developed a library using NestJS, and part of our module's code is as follows:

cache.service.ts

@Injectable()
export class CacheService implements OnModuleInit {
  constructor(
    private readonly discoveryService: DiscoveryService,
    private readonly scanner: MetadataScanner,
    private readonly reflector: Reflector,
  ) {}

cache.module.ts

@Module({
  imports: [DiscoveryModule],
  providers: [CacheService],
})
export class CacheModule {}

However, one of the users of our library has encountered the following error:

ERROR \[ExceptionHandler\] Nest can't resolve dependencies of the CacheService (DiscoveryService, MetadataScanner, ?). Please make sure that the argument Reflector at index \[2\] is available in the CacheModule context.

Potential solutions:

- Is CacheModule a valid NestJS module?
- If Reflector is a provider, is it part of the current CacheModule?
- If Reflector is exported from a separate @Module, is that module imported within CacheModule?
  @Module({
  imports: \[ /\* the Module containing Reflector \*/ \]
  })
  The user has structured their project using Bun, and their app.module.ts looks like this:
@Module({
  imports: [CacheModule],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

I have attempted the following solutions:

  1. Considering it might be a compatibility issue with Bun, I created and built a simple project using Bun, which worked fine.
  2. Suspecting a problem with the tsconfig, I changed the settings to those of a working configuration, but the issue persisted.
  3. When I replicated the structure of cache.service.ts within the problematic project and modularized it, then imported it into app.module.ts, the Reflector was successfully injected and the application ran as expected. This leads me to believe that the issue arises when using the modularized module externally.

Is this the root cause? If so, why? If not, how can we resolve this issue? In other projects, it mostly builds and runs fine.

I've attached the github link of the code that the user said they were having issues with. https://github.com/saint6839/sample/blob/main/apps/nestjs-boilerplate/modules/app/app.module.ts

0

There are 0 best solutions below