Skip to content

Conversation

@mehdiraized
Copy link

Issue #118

Root Cause

  • The memory/redis provider packages require keyv at runtime but do not declare it as a dependency. In many local/monorepo installs keyv is accidentally present via hoisting/resolutions, but in production (or a clean install) it’s missing, so require('keyv') fails and the main plugin reports the generic “Could not load REST Cache provider "memory"” error.
  • Additionally, the providers currently assume ESM-style default exports (require('keyv').default, new QuickLRU.default(...), new KeyvRedis.default(...)). Depending on which version/module-shape is installed, this can produce TypeError: Keyv is not a constructor (Node 22 reports in the issue).

Code Changes

  • Add keyv as a direct dependency of:
  • @strapi-community/provider-rest-cache-memory
  • @strapi-community/provider-rest-cache-redis
  • Make the providers resilient to both CJS and ESM module shapes by switching to “default-or-module” resolution:
  • const keyvModule = require('keyv'); const Keyv = keyvModule.default ?? keyvModule;
  • const quickLruModule = require('quick-lru'); const QuickLRU = quickLruModule.default ?? quickLruModule;
  • const keyvRedisModule = require('@keyv/redis'); const KeyvRedis = keyvRedisModule.default ?? keyvRedisModule;
  • Update the constructors to use new QuickLRU(...) and new KeyvRedis(...) accordingly.
  • Improve the provider loader error to include the underlying failure reason (missing dependency / ESM interop), so users don’t get misled into repeatedly reinstalling the provider package.

Verification

  • Validate a clean install scenario:
  • Install only @strapi-community/plugin-rest-cache in a fresh Strapi 5 app and start it with provider memory.
  • Validate Node runtime behavior:
  • Start the memory playground under Node 20 and Node 22; ensure no “provider cannot load” and no “Keyv is not a constructor”.
  • Smoke-test redis provider load (module import + initialization), ensuring the same interop fixes apply.

Deliverables

  • Patch to provider package.json files (adds missing dependency).
  • Patch to provider runtime code (robust imports for Node 20/22).
  • Better runtime error message when a provider fails to load.

- Add explicit 'keyv' dependency to provider packages for compatibility
- Fix default export handling for 'keyv' and '@keyv/redis' modules
- Enhance bootstrap error messages with specific loading failure details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant