tj / connect-redis

Redis session store for Connect
MIT License
2.79k stars 344 forks source link

TypeScript CommonJS/ESM #411

Open rmuchall-sepa opened 1 month ago

rmuchall-sepa commented 1 month ago

Hi there,

If possible, please could you consider making RedisStore a named export?

export class RedisStore extends Store {

At the moment, with the default only export it is not possible to use connect-redis in a TypeScript shared library with interoptability between CommonJS and ESM. This is because of the way TypeScript transpiles between CommonJs/ESM.

// Original TypeScript (default export)
import RedisStore from "connect-redis";

// Transpiled to ESM (works correctly)
import RedisStore from "connect-redis";

// Transpiled to CJS (broken)
const RedisStore = require("common-js"); // note the missing .default

If RedisStore is a named export then the code becomes:

// Original TypeScript (named export)
import {RedisStore} from "connect-redis";

// Transpiled to ESM (works correctly)
import {RedisStore} from "connect-redis";

// Transpiled to CJS (works correctly)
const RedisStore = require("connect-redis");
const store = new RedisStore.RedisStore(...);

Thanks for your consideration :)

wavded commented 1 month ago

This is on my radar for the next release. Thanks for reporting!

github-actions[bot] commented 2 weeks ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.