skip to Main Content

I am working on search with redis (redis-om) in new NextJS 13 (app directory). When I go by tutorial I am getting following error with Entity. I actually don’t know if it is bug or I am doing something wrong. Thanks for any advice.

Code


import { Client, Entity, Schema, Repository } from "redis-om";

const client = new Client();

async function connect() {
  if (!client.isOpen()) {
    console.log("redis url", process.env.REDIS_URL)
    await client.open(process.env.REDIS_URL);
  }
}

class Coin extends Entity {}

let schema = new Schema(
  Coin,
  {
    id: { type: "string"},
    symbol: { type: "string"},
    name: { type: "text", textSearch: true },
  },
  {
    dataStructure: "JSON",
  }

Error

- error lib/redis.ts (14:21) @ Entity
- error Class extends value undefined is not a constructor or null

This might be caused by a React Class Component being rendered in a Server Component, React Class Components only works in Client Components. Read more: https://nextjs.org/docs/messages/class-component-in-server-component

I tried to use it as a client, but it is not working as well. Also nodejs server could work too, but I would like to keep it in NextJS app.

2

Answers


  1. Chosen as BEST ANSWER

    Thank you, the tutorial worked for me! However I found another issue that NextJS 13 doesn't work properly with top-level await feature of new Javascript. So I had to remake it.


  2. This tutorial was written for Redis OM 0.2, which is reflected in the package.json. Redis 0.3 should work fine with it.

    However, Redis OM 0.4 introduced breaking changes which eliminated the Entity class. I’m guessing you entered:

    npm install redis-om
    

    This would give you that latest version (i.e 0.4) which isn’t compatible with this tutorial.

    I would recommend sticking with the upgraded version and checking out the documentation in the README or following this similar but upgraded tutorial.

    Note that I am the author of Redis OM and both tutorials. Updating the example on redis.io is in my backlog.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search