ioredis icon indicating copy to clipboard operation
ioredis copied to clipboard

ESM Wrapper Module

Open Exnadella opened this issue 3 years ago • 7 comments

This is a Feature request.

We like to use the IOredis to connect to the RedisJson and looking for a ESM style import to be able to use in our project. Could you please provide a Wrapper to be able to use this with ESM style along with Web Components in polymer.

We like to import as a component and define the connection.

Please refer this link for our requirement. https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1

Exnadella avatar Jan 28 '22 11:01 Exnadella

Hey @Exnadella,

Thanks for raising this up. I did consider working on a wrapper, but the idea of the dual package has a pitfall that a project may end with loading two versions of ioredis: https://nodejs.org/api/packages.html#dual-package-hazard. That means we have to review and make changes accordingly to make sure the situation won't break functionalities. Given ioredis is a server-side package, I don't see enough benefits compared to the pitfall.

In the meantime, if the Node.js community thinks CJS will be deprecated, I'd like to migrate ioredis to be a pure ESM module in the next major release. Unfortunately, that isn't the case yet.

Anyway, I'm open to any suggestions on this.

luin avatar Jan 28 '22 11:01 luin

Hi,

Thanks for the quick response.

Since you said its on Server side, Can you work on a polymer component which can send data to your server via an API and we have the component published in polymer.

https://github.com/Polymer https://github.com/PolymerElements https://github.com/PolymerElements/iron-ajax https://www.npmjs.com/package/@polymer/iron-ajax

We can provide KT on polymer how to use it and see if we can build something that can connect to the server.

Exnadella avatar Jan 28 '22 13:01 Exnadella

@luin I work with Serverless and use ioredis in Lambda functions. Because of CJS, ioredis is included in every function that I have, even if it is not needed. ESM could help me a lot to decrease the package size.

pabacham avatar Jan 28 '22 14:01 pabacham

@luin Do you think just adding .cjs in the extension will help as Node moves ahead every version ? else loading the module in newer versions is becoming impossible...

LRagji avatar Jul 07 '22 15:07 LRagji

@LRagji hi, can you elaborate a little bit more? I'm not sure if I got the point. Why adding .cjs helps?

luin avatar Jul 07 '22 15:07 luin

To load ioredis into new mjs modules... since most new application will be written in ESM modules now we can explicitly mention its of type esm or cjs with extension and then backward loading is supported in ESM as i read here https://adamcoster.com/blog/commonjs-and-esm-importexport-compatibility-examples

LRagji avatar Jul 07 '22 15:07 LRagji

Given that esm is very helpful in serverless environments and more and more frameworks use it (vite, nuxt, rollup, ...), it would be nice if ioredis could provide esm modules.

tobiasdiez avatar Sep 17 '22 12:09 tobiasdiez

@Exnadella recent release mentions support of ESM.

mcrawshaw avatar Jan 22 '23 01:01 mcrawshaw

As @mcrawshaw said, the latest version added import { Redis } from 'ioredis' support for ESM packages so closing. Feel free to reopen if the issue persists.

luin avatar Jan 22 '23 05:01 luin

While this direct import is nice (and maybe helpful in certain situations involving ESM), the distributed package still seems to only ship CJS and no ESM. Thus one cannot make use of the ESM features, like tree shaking, to reduce the size of the final package which is important for edge distributions on Azure Functions or AWS Lambda.

Thus it would be nice if an ESM-version of ioredis would be available. There are also build tools such as https://github.com/unjs/unbuild that make it easy to ship ESM and CJS versions at the same time.

tobiasdiez avatar Jan 22 '23 07:01 tobiasdiez

@tobiasdiez Have you find a solution ready to go , or you build your own ?

xlanex6 avatar Nov 28 '23 11:11 xlanex6