#CacheModule registerAsync cant resolve
24 messages · Page 1 of 1 (latest)
Can you provide any errors and related configurations?
Suggestion for @wanton imp:
When asking for help with a problem, don't just say, "X doesn't work" or "Y did not fix it" actually describe the error.
If there is an error message, share it. If it did not function as expected, describe how it behaved and how you expected it to behave.
If you haven't already, or haven't recently, share the code that is not working and any code we may need to help diagnose the error.
error reference: https://pastebin.fr/138308
pastebin - outil de debug collaboratif
code references: https://pastebin.fr/138309
pastebin - outil de debug collaboratif
the error says WidgetModule but you didn't show us WidgetModule's code
@dusky tendon that is just one of many other modules that make use of Cache manager, so in *Modules there is no reimporting of CacheModule which is imported globally on app module, and I'd expect it becomes available to all further modules, since registering it globally.
All what other modules do is: at constructor inject a cacheManager instance to make use of it. Basically: @Inject(CACHE_MANAGER) private readonly cacheManager: Cache
In the async version, you're missing setting isGlobal. Also, it is better practice to create a cache service with the module, to then export it and use it (import it) where you actually need it (i.e. don't make it global).
@vague flower thanks for your feedback, it did not change the outcome, still getting same error.
Did you try creating a service?
No, I understand what you're suggesting. If our team will agree will try having it implemented like that.
However this seems to be an issue in Nestjs, hope it gets fixed anytime soon.
You could also try adding @Global above the module definition for your cache module.
My guess is, modules are imported faster than cache config factory resolved.
@vague flower I'll try that too now.
But, again. The "normal" way to introduce the cache module is to build your own cache module with a service (which is smarter, because you can control the logic better in what is stored and how).
And then import that module only where you need it.
I'm just stuck on registering cache module with factory evaluation and hardcoded mode.
Hardcoded mode with global flag works instantly.
Factory mode with registerAsync fails to provide cacheService where used, no matter if there is global flag or not.
So plain simple, hardcoded works, env vars via configService does not work.