BJS-kr / nestjs-omacache

flexible, powerful and simple caching strategy using decorators for NestJS
86 stars 4 forks source link

Nest can't resolve dependencies of the CacheService (DiscoveryService, MetadataScanner, ?) #8

Closed Dugnist closed 7 months ago

Dugnist commented 7 months ago
 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 */ ]
  })

My "app.module.ts":

// Node modules
import { Module } from '@nestjs/common';
import { RateLimiterModule } from 'nestjs-rate-limiter';
import { CacheModule } from 'nestjs-omacache';
// APP Modules
import { DBModule } from 'modules/db/db.module';
import { AuthModule } from 'modules/auth/auth.module';
import { UsersModule } from 'modules/users/user.module';
import { AccessModule } from 'modules/access/access.module';
import { ProfileModule } from 'modules/profiles/profiles.module';
import { SettingsModule } from 'modules/settings/settings.module';
// Controllers
import { AppController } from './controllers/app.controller';
// Services
import { AppService } from './services/app.service';

@Module({
  imports: [
    // First load modules:
    RateLimiterModule,
    CacheModule,
    DBModule,
    // Business logic modules:
    AuthModule,
    UsersModule,
    AccessModule,
    ProfileModule,
    SettingsModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

OSX Node v20.7.0 @nestjs/common": "^10.0.0" @nestjs/core": "^10.0.0"

BJS-kr commented 7 months ago

Got it. I'll see what the problem is

saint6839 commented 7 months ago

Hello!☺️ I'm one of the contributors to the nestjs-omacache package. Thank you for bringing this issue to our attention.

We're diligently reviewing your issue and attempting to reproduce it. However, reproducing it in our environment has proven to be challenging. To move forward, we kindly request the following two actions from you:

  1. As indicated by the error message you've encountered, it seems the issue may stem from a missing Reflector dependency. Please try adding an explicit dependency for Reflector in your AppModule.

  2. If the issue persists after trying the first suggestion, could you please provide a link to your complete code or a link to a minimal reproducible example of the same bug? This would greatly aid us in diagnosing and addressing the issue more effectively.

Thank you for your cooperation and understanding. We're looking forward to your response.

Dugnist commented 7 months ago

empty_starter.zip

Thank you for your quick response - I'm attaching a clean project with all the settings and the imported Reflector

saint6839 commented 7 months ago

empty_starter.zip

Thank you for your quick response - I'm attaching a clean project with all the settings and the imported Reflector

We will check and get back to you this week. Thank you :)

saint6839 commented 7 months ago

empty_starter.zip

Thank you for your quick response - I'm attaching a clean project with all the settings and the imported Reflector

Thank you for your patience. To diagnose the root cause of the issue, I've made modifications to several parts of the code within the attached files:

Additionally, suspecting a potential issue with the way Bun resolves dependencies (though I'm not entirely certain of the specifics), I opted to install dependencies using npm instead of Bun. As a result, I was able to confirm that the dependency issues related to CacheModule were successfully resolved.

Due to space limitations, we have attached the resolved file to the email address listed in your Github profile. Let me know if you need any further help :)

image