OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

TypeError: Class extends value undefined is not a constructor or null while creating adapter

  • Thread starter Thread starter Raman Prajapat
  • Start date Start date
R

Raman Prajapat

Guest
So I am creating a node application and implementing io redis for socket emmiter. I am creating adapter but getting error. class ShardedRedisAdapter extends socket_io_adapter_1.ClusterAdapter { ^ TypeError: Class extends value undefined is not a constructor or null

Code:
import express, { Application } from "express";
import cors from "cors";
import RequestHandler from "./api";
import "reflect-metadata";
import "es6-shim";
import listEndpoints from "express-list-endpoints";
import "./db.config";
import { globalErrorHandler } from "./middlewares/Error";
import cookieParser from "cookie-parser";
import { createServer } from "http";
import { Server } from "socket.io";
import { createAdapter } from "@socket.io/redis-adapter";
import { Redis } from "ioredis";

const app: Application = express();

const CorsOptions = {
  credentials: true,
  origin: true,
  methods: ["GET", "POST", "PUT", "PATCH", "DELETE"],
  allowedHeaders: ["Content-Type"],
};
app.use(cors(CorsOptions));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());

RequestHandler(app);
app.use(globalErrorHandler);
console.log(listEndpoints(app as express.Express));

export const httpServer = createServer(app);

const pubClient = new Redis(6379, "localhost", {
  password: process.env.REDIS_PASSWORD,
});

const subClient = new Redis(6379, "localhost", {
  password: process.env.REDIS_PASSWORD,
});

const io = new Server(httpServer, {
  adapter: createAdapter(pubClient, subClient),
});

io.on("connection", (socket) => {
  console.log("a user connected");

  socket.on("disconnect", () => {
    console.log("user disconnected");
  });
});

httpServer.listen(process.env.PORT || 9001, () => {
  console.log(`🚀️ Server is running on port ${process.env.PORT || 9001}`);
});

I was trying to connect ioredis with my application to emit events.

This is my docker compose file

Code:
version: "3"
services:
  postgres:
    image: postgres:15
    container_name: server-postgres
    restart: unless-stopped
    ports:
      - ${POSTGRES_PORT}:5432
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    volumes:
      - postgres:/var/lib/postgresql/data
  pgadmin:
    image: dpage/pgadmin4
    container_name: pgadmin4_container
    restart: always
    ports:
      - "8888:80"
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD}
    volumes:
      - pgadmin-data:/var/lib/pgadmin
  redis:
    image: redis/redis-stack
    container_name: server-redis
    restart: unless-stopped
    ports:
      - ${REDIS_PORT}:6379
      - ${REDISINSIGHT_PORT}:8001
    environment:
      - REDIS_ARGS=--requirepass ${REDIS_PASSWORD}
    volumes:
      - redis:/data
      - ./redis.conf:/usr/local/etc/redis
  server:
    image: server-dev
    build:
      context: .
      target: server-dev
      args:
        - PORT:${PORT}
    container_name: server-dev
    restart: unless-stopped
    ports:
      - ${PORT}:${PORT}
    depends_on:
      - postgres
      - redis
    volumes:
      - .:/server/
volumes:
  pgadmin-data:
  postgres:
    name: server-postgres
  pgadmin:
    name: pgadmin-data
  redis:
    name: server-redis
networks:
  default:
    name: server

<p>So I am creating a node application and implementing io redis for socket emmiter. I am creating adapter but getting error.
class ShardedRedisAdapter extends socket_io_adapter_1.ClusterAdapter {
^
TypeError: Class extends value undefined is not a constructor or null</p>
<pre><code>import express, { Application } from "express";
import cors from "cors";
import RequestHandler from "./api";
import "reflect-metadata";
import "es6-shim";
import listEndpoints from "express-list-endpoints";
import "./db.config";
import { globalErrorHandler } from "./middlewares/Error";
import cookieParser from "cookie-parser";
import { createServer } from "http";
import { Server } from "socket.io";
import { createAdapter } from "@socket.io/redis-adapter";
import { Redis } from "ioredis";

const app: Application = express();

const CorsOptions = {
credentials: true,
origin: true,
methods: ["GET", "POST", "PUT", "PATCH", "DELETE"],
allowedHeaders: ["Content-Type"],
};
app.use(cors(CorsOptions));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());

RequestHandler(app);
app.use(globalErrorHandler);
console.log(listEndpoints(app as express.Express));

export const httpServer = createServer(app);

const pubClient = new Redis(6379, "localhost", {
password: process.env.REDIS_PASSWORD,
});

const subClient = new Redis(6379, "localhost", {
password: process.env.REDIS_PASSWORD,
});

const io = new Server(httpServer, {
adapter: createAdapter(pubClient, subClient),
});

io.on("connection", (socket) => {
console.log("a user connected");

socket.on("disconnect", () => {
console.log("user disconnected");
});
});

httpServer.listen(process.env.PORT || 9001, () => {
console.log(`🚀️ Server is running on port ${process.env.PORT || 9001}`);
});

</code></pre>
<p>I was trying to connect ioredis with my application to emit events.</p>
<p>This is my docker compose file</p>
<pre><code>version: "3"
services:
postgres:
image: postgres:15
container_name: server-postgres
restart: unless-stopped
ports:
- ${POSTGRES_PORT}:5432
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- postgres:/var/lib/postgresql/data
pgadmin:
image: dpage/pgadmin4
container_name: pgadmin4_container
restart: always
ports:
- "8888:80"
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD}
volumes:
- pgadmin-data:/var/lib/pgadmin
redis:
image: redis/redis-stack
container_name: server-redis
restart: unless-stopped
ports:
- ${REDIS_PORT}:6379
- ${REDISINSIGHT_PORT}:8001
environment:
- REDIS_ARGS=--requirepass ${REDIS_PASSWORD}
volumes:
- redis:/data
- ./redis.conf:/usr/local/etc/redis
server:
image: server-dev
build:
context: .
target: server-dev
args:
- PORT:${PORT}
container_name: server-dev
restart: unless-stopped
ports:
- ${PORT}:${PORT}
depends_on:
- postgres
- redis
volumes:
- .:/server/
volumes:
pgadmin-data:
postgres:
name: server-postgres
pgadmin:
name: pgadmin-data
redis:
name: server-redis
networks:
default:
name: server

</code></pre>
 
Top