cache-manager: NestJS v9 incompatible with version 5
i get this error
TypeError: store.get is not a function
at Object.get (.../node_modules/cache-manager/src/caching.ts:88:36)
at AppController.getHello
Im implementing caching following the NestJS docs.
this is my posting on stackoverflow (https://stackoverflow.com/questions/73908197/typeerror-store-get-is-not-a-function-nestjs-cache-manager)
but when im switch to version4 then its working… but i dont know why.
i wonder this is just my fault or version issue
-> i try to find difference but i think get method’s logic is same(using lru-cache package). so maybe type issue?
if this is my fault, then can you tell me how to solve it?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 25
- Comments: 35 (8 by maintainers)
Commits related to this issue
- Update nestJS to last version to work with cache-manager v5 (https://github.com/node-cache-manager/node-cache-manager/issues/210) — committed to EmileCalixte/nestjs-openfoodfacts by EmileCalixte a year ago
- fix(avo-2740): revert cache-manager to v4 v5 is incompatible with nestjs https://github.com/node-cache-manager/node-cache-manager/issues/210 — committed to viaacode/react-admin-core-module by bertyhell a year ago
For the ones using
cache-manager-redis-store, you also need to downgrade it to v2.0.0 (instead of 3.0.1).After some investigation, it appears the
cachingmethod’s signature has changed to now accept a factory as the first parameter and options as the second vs the old single options object that included the store. Nest will need to update some code to support v5, but I make no guarantees if we’ll concurrently support v4 and v5 or just v4 until Nest v10 is released.This change was rather hard to find as the old
lib/cachingand the newsrc/cachinghave different git histories and there’s no changelog explicitly mentioning this changeIf you are coming here from the NestJS caching Redis tutorial, use these dependencies:
@vincentwinkel thanks
I managed to solve this with:
My module file:
My provider file:
You are welcome.
My fix for NestJS was to downgrade to
"cache-manager": "^4.0.0",.This is also forced by @micalevisk 's PR here.
I’m no longer the maintainer of this project, but:
But I also agree that the constructors should not be async.
Fixed in nest@9.2.0
Thanks all!!
I can confirm that using the latest NestJS version (9.2.1) solves this issue for me. Looks like anything north of 9.1.3 should address the issue, which is when this was merged: https://github.com/nestjs/nest/commit/4eb5fb00a3f945e73087aab0d578661c0939dbf6
@srinivasan-getstan there’s nothing really to update. botika was kind enough to provide an example of how to use
cache-manager@^5with Nest if you want to use that until a stable fix gets merged in with Nest’s code base. Otherwise, v5 s a breaking change and you should use v4 for the old functionality. ThisPR should fix any usage issues between v4 and v5, at least in the tests I’ve done when creating it, but we’ll have to wait for it to get merged in and published, which may take a bit. Until then, as I said, there’s nothing cache-manager needs to do about this, they correctly released a major change, which can include breaking changes, and that’s that.+1 for a fix.
I believe this is the commit that broke everything. A “Breaking Changes” should have been issued.
same here…back to version @4.1.0 and wait
to resolve that i need to change the “cache-manager”: “^4.0.0”, and if you use redis “cache-manager-redis-store”: “2.0.0”, this resolved from me
Hi. This still does not work for me even after updating it to 9.2.0. Below is the code for initiating CacheModule in
app.module.ts:Versions: cache-manager: 5.1.6 redis:3.1.2 cache-manager-redis-store:3.0.1
@WaylonOKC as this was over a semver major version, a breaking change was fine. It’s just that until now, Nest’s peerDeps were okay with any version of
node-cache-manager. Therefore, no “fix” is necessary from this library. I’ll be working on an update for Nest to figure out if support ing v4 and v5 simultaneously is possibleThe awser is in the last post. And install Linux, archlinux, https://wiki.archlinux.org/title/installation_guide
This is work for me. redis: “^3.1.2” cache-manager: “^5.1.3” cache-manager-redis-store: “^3.0.1”
It should be noted that
this.cacheManager.set(key, value, { ttl } as any);node-cache-managerversion 5 does not work withNestversion 8 eitherBasically, I did https://github.com/node-cache-manager/node-cache-manager/commit/12020d8de62142d47c28dba0cf1f820328488663 and remove it. I would use version 4 until nest is updated or you can use that module. There are also not many updated Stores yet.
Breaking changes are often expected by a major version, but they definitely should be called out and not just left to be discovered after people upgrade.
FWIW, this thread started out as a “TypeError” and not specifically a NestJS incompatibility.
same here