#can not use store setting in usefactory

1 messages ยท Page 1 of 1 (latest)

hushed veldt
#

What's the problem? Functionality, type issue, something else?

strange bloom
#

How did you import redisStore ? If it is from "cache-manager-redis-store", you have to import it like this :

import * as redisStore from 'cache-manager-redis-store';

stoic gazelle
#

I need my cake and eat it to situation

strange bloom
#

My configuration works like this :

CacheModule.registerAsync({ imports: [ConfigModule], useFactory: (config: ConfigService) => ({ store: redisStore, host: config.get('REDIS_HOST'), port: config.get('REDIS_PORT'), auth_pass: config.get('REDIS_PASSWORD'), }), inject: [ConfigService] }),

#

Maybe your config is not exact ?

stoic gazelle
# strange bloom My configuration works like this : ` CacheModule.registerAsync({ impor...

still get this

(property) CacheModuleAsyncOptions<{ store: typeof import("/home/weshuiz13/Documents/app/nest-server/node_modules/cache-manager-redis-store/dist/index"); host: string; port: number; }>.useFactory?: (...args: any[]) => CacheModuleOptions<{
    store: typeof redisStore;
    host: string;
    port: number;
}> | Promise<CacheModuleOptions<{
    store: typeof redisStore;
    host: string;
    port: number;
}>>
strange bloom
#

It's the full error ?

stoic gazelle
#

yes

strange bloom
#

Can you show the whole module ?

stoic gazelle
#

that is going to be the app module tho

#

seems the error was pointing out store: typeof redisStore;

#

idk why it wanted typeof but the error is gone at least

#

but the problem is not fully gone tho

Nest can't resolve dependencies of the TwoFactorService (AccountService, PrismaService, ?). Please make sure that the argument CACHE_MANAGER at index [2] is available in the TwoFactorControllerModule context.

Potential solutions:
- If CACHE_MANAGER is a provider, is it part of the current TwoFactorControllerModule?
- If CACHE_MANAGER is exported from a separate @Module, is that module imported within TwoFactorControllerModule?
  @Module({
    imports: [ /* the Module containing CACHE_MANAGER */ ]
  })
strange bloom
#

It's just the typescript typing, you don't want to put "typeof redisStore" in your config

stoic gazelle
#

then how do i solve it?

#

welp @ts-ignore then

strange bloom
#

"cache-manager-redis-store does not support redis v4. In order for the ClientOpts interface to exist and work correctly you need to install the latest redis 3.x.x major release. See this issue to track the progress of this upgrade."

#

You saw this ?

strange bloom
#

ok

stoic gazelle
#
- If CACHE_MANAGER is a provider, is it part of the current TwoFactorControllerModule?
- If CACHE_MANAGER is exported from a separate @Module, is that module imported within TwoFactorControllerModule?

but CACHE_MANAGER is neither a service or a module

strange bloom
#

If you defined the CacheModule config isGlobal: true it should work in others modules ..

#

that's weird

stoic gazelle
# strange bloom that's weird

didn't put the global back, but now i did still the same thing...

CacheModule.registerAsync({
      imports: [ConfigModule],
      // @ts-ignore
      useFactory: (config: ConfigService) => ({
        isGlobal: true,
        store: redisStore,
        host: config.redis.host,
        port: config.redis.port,
      }),
      inject: [ConfigService],
    }),
#

the only module that comes before the CacheModule is the configModule

ConfigModule.forRoot({
      isGlobal: true,
      cache: true,
      expandVariables: true,
      envFilePath: `./config/env/.${process.env.NODE_ENV}.env`,
      //load: [config],
    }),
strange bloom
#

You should use : configService.get('ENV_VAR_HERE') no ?

stoic gazelle
strange bloom
#

You don't have any stacktrace for the errors ?

strange bloom
stoic gazelle
#

srry had to share a txt, no nitro ๐Ÿ˜…

strange bloom
#

If TwoFactorService is part of a provider module that is import in your AppModule + you defined the isGlobal: true in the CacheModule configuration... it should work ๐Ÿ˜

stoic gazelle
#

yes it is part of the app module

#

i would be making a min repo if i could, but this thing got so big i just cant anymore

strange bloom
#

Ok.. sorry

stoic gazelle
#

no i'm sorry here ๐Ÿ˜…

hushed veldt
stoic gazelle
stoic gazelle
#

i start to hate this cache

stoic gazelle
#

setup a new project to see what went wrong
figured it out

but now i want to do

CacheModule.registerAsync({
      imports: [ConfigModule],
      inject: [apiConfigService],// custom service
      // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      // @ts-ignore
      useFactory: async (config: apiConfigService) => ({
        host: config.redis.host,
        port: config.redis.port,
        ttl: config.redis.ttl,
        store: redisStore,
        isGlobal: true,
      }),
    }),

but what do i do wrong here?

hushed veldt
#

Is your injection token apiConfigService?

stoic gazelle
#

cant /close it anymore?