Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: RedisStore is not a constructor #418

Closed
J0hn3ch opened this issue Dec 11, 2024 · 11 comments
Closed

TypeError: RedisStore is not a constructor #418

J0hn3ch opened this issue Dec 11, 2024 · 11 comments

Comments

@J0hn3ch
Copy link

J0hn3ch commented Dec 11, 2024

Hi everyone,

In one of my projects, a strange TypeError appear when I switch from Node.js v20.15.0 to Node.js v22.12.0 .
When I try to create a new RedisStore instance this type error occurs :

let redis_store = new RedisStore({
                  ^

TypeError: RedisStore is not a constructor
    at Object.<anonymous> (/home/***/db.js:164:19)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/home/***/app.js:27:25)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)

Node.js v20.15.0

I find that the error can be solved using const { RedisStore } = require("connect-redis"); in the project with Node.js v22.12.0 with connect-redis version ^8.0.1.


Previously I used const RedisStore = require("connect-redis").default; in the project with Node.js v20.15.0 with connect-redis version ^7.1.1

Is there some reason why I cannot use the the same line of code in both version ?

@wavded
Copy link
Collaborator

wavded commented Dec 11, 2024

I am running Node 23 currently without issues. Do you have a small project that duplicates this issue?

Is there some reason why I cannot use the the same line of code in both version ?

We ran into compatibility issues between CommonJS and ESM projects, this makes one common API. (see #411)

@beauspot
Copy link

I am currently running into a similar issue and to make matters worst what I am getting is that RedisStore is an interface & not a class, now when I go into the module, I find out that there is both a class & an interface that uses the "RedisStore" as a variable and both are been and now I cannot work with it. this is what I am getting when I import RedisStore as an object: (alias) interface RedisStore
import RedisStore and it's supposed to be a class. Please can someone help me with this?
redis-store-src
redis-store-types

@wavded
Copy link
Collaborator

wavded commented Dec 31, 2024

Not sure what's going on there. That second screenshot you shared looks incorrect. It almost looks like you maybe installed the @types/connect-redis package? That is legacy and should not be installed with recent versions of connect-redis as the types are already included.

@beauspot
Copy link

beauspot commented Jan 1, 2025

Not sure what's going on there. That second screenshot you shared looks incorrect. It almost looks like you maybe installed the @types/connect-redis package? That is legacy and should not be installed with recent versions of connect-redis as the types are already included.

Thank you very much I would attempt to delete the @types/connect-redis module and attempt it again oh and Happy new year from Nigeria.

@zackyjc
Copy link

zackyjc commented Jan 2, 2025

If redisClient is undefined, it will cause error.

try it:

var redisClient = await createClient({})...
var redisStore = new RedisStore({
		client: redisClient
	});

@beauspot
Copy link

beauspot commented Jan 2, 2025

Are you installing the "@types/connect-redis" dependency ?

@MayurVirkar
Copy link

I am facing the exact same issue. I am on node 23.5
I am using
"connect-redis": "^8.0.1",
With
"ioredis": "^5.4.2",

Section of my code

const RedisStore = require('connect-redis');
const Redis = require('ioredis');

const client = new Redis({
    db: config.redisSessionDatabaseIndex
});

let redisStore = new RedisStore({
    client: client
});

error

let redisStore = new RedisStore({
                 ^

TypeError: RedisStore is not a constructor
    at Object.<anonymous> (app.js:27:18)

@tigermax139
Copy link

That's an issue on Node.js 22 and lower.
The quick and dirty solution is just implementing connect interface manually. (See index.ts for inspiration)

@MayurVirkar
Copy link

I am on nodejs 23.5

@basithsabdul
Copy link

Same problem with Node.js v22.13.0 also. Only if we initialize "const { RedisStore } = require("connect-redis");" the error is not occurring.

Node.js v22.13.0
├── [email protected]
└── [email protected]

@wavded
Copy link
Collaborator

wavded commented Feb 17, 2025

There is no default export anymore in Redis v8. See v8 release migration notes and latest readme:

For CommonJS-style imports it should look like:

const { RedisStore } = require("connect-redis");

@wavded wavded closed this as completed Feb 17, 2025
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

No branches or pull requests

7 participants