Skip to content

Cannot run Next.js v14 with node-redis 4 by following quickstart documentation #1062

@JohnJasonFisher

Description

@JohnJasonFisher

Brief Description of the Bug
Please forgive me if I'm missing something obvious, but I cannot confirm that this package to persist my cached static site pages or any other data into Redis by following the introduction documentation.

It seems like when I follow the introduction documentation and add the debug env var, I can see the debug logs but after I visit the home page or a static page like the 404 site, I cannot see any cached next.js data in my Redis instance.

Severity
[Critical]

Frequency of Occurrence
[Always]

Steps to Reproduce
Provide detailed steps to reproduce the behavior, including any specific conditions or configurations where the bug occurs:

Follow the introduction documentation here https://caching-tools.github.io/next-shared-cache/installation

  1. Have a local Redis instance running

  2. Create a new Next.js v14 app with the command npx create-next-app@next-14

    • Saw no to app router, use the page router
    • Say no to tailwind
    • See screenshot
      Image
  3. Install the package with npm i @neshca/cache-handler

  4. Install node-redis 4 with the command npm i redis@maintenance-v4

  5. Create a .env file and paste NEXT_PRIVATE_DEBUG_CACHE=1. Following the example here: https://caching-tools.github.io/next-shared-cache/troubleshooting#method-2-debug-mode

  6. Create a cache-handler.mjs file. Based on this redis integration example page: https://caching-tools.github.io/next-shared-cache/redis

  7. Rename the the next.config.mjs file to next.config.js and update the next.config.js file to include the cache handler

/** @type {import('next').NextConfig} */
module.exports = {
  cacheHandler: require.resolve("./cache-handler.mjs"),
  experimental: {
    instrumentationHook: true,
  },
};
  1. Follow the "populate the Cache with Prerendered Pages" step by creating an instrumentation.ts file and adding the following:
export async function register() {
  if (process.env.NEXT_RUNTIME === "nodejs") {
    const { registerInitialCache } = await import(
      "@neshca/cache-handler/instrumentation"
    );
    // Assuming that your CacheHandler configuration is in the root of the project and the instrumentation is in the src directory.
    // Please adjust the path accordingly.
    // CommonJS CacheHandler configuration is also supported.
    const CacheHandler = (await import("./cache-handler.mjs")).default;
    await registerInitialCache(CacheHandler);
  }
}
  1. Build and run the app with npm run build && npm run start
  2. Visit localhost:3000 and then visit localhost:3000/notfound
  3. Observe that the debug logs
using custom cache handler @neshca/cache-handler is not configured yet
[CacheHandler] Instance created with provided context.

But no cached page data can be found in Redis. I'm running keys * in Redis to confirm this.

Expected vs. Actual Behavior
Expected: To be able to see data in Redis after visiting the home page and a static page like the 404 page and seeing a key pre-pended with 'prefix:*' in Redis.

Screenshots/Logs

Image

Image

Environment:

  • OS: MacOS
  • Node.js version: v20.18.2
  • @neshca/cache-handler version: 1.9.0
  • next version: 14.2.29

Dependencies and Versions
"redis": "^4.7.1"

Impact of the Bug
I'm not able to confirm if I have this package working with my app.

Additional context
Hope that helps! I want to be able to use this package because I want a simple way to centrally store my SSG pages in Redis.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions