ESM vs CJS #279
Replies: 3 comments 8 replies
-
I'd rather the library didn't go ESM only. For now, I'm stuck with CJS, because NestJS currently only supports CJS (see nestjs/nest#8736). I'd be fine with a double CJS/ESM build for now, to ease migration. |
Beta Was this translation helpful? Give feedback.
-
Some libraries are ESM only for the latest major version and keep maintaining an older version with CJS for some time. That is also a good approach. |
Beta Was this translation helpful? Give feedback.
-
Hey there! I recently forked this library to see how much work it would be to get an ESM version up an running. You can see my branch here: https://github.com/opiation/oauth2-server/tree/chore/convert-to-esm The tests run and all pass (with 2 changes to line numbers in an expected stacktrace). Sorry for all the whitespace changes. My local setup automatically ran prettier on everything. I can undo those changes if needed. I haven't added any automation to bundle the code into both CJS and ESM format but I think that shouldn't be too much effort using the "exports": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"default": "./index.js", // not sure about the appropriate default here though I don't know when it would get used
} I could submit my FWIW, there are other changes I plan to make including, Prettier automatic formatting, TypeScript type annotations in JS Doc comments (testable with Anyways, to the maintainers here @jankapunkt et al., let me know what you think! Happy to discuss this further if any of this is close to but not exactly what you're looking for. |
Beta Was this translation helpful? Give feedback.
-
This module is, for historical reasons, still CJS-only. However, there is currently a shift in the overall ecosystem, where many packages move towards ESM-only. A direct consequence is already here: we currently cannot install amnd use chai @ 5.x as it's esm-only now. This situation will rather increase than decrease.
Therefore I was thinking what we should do:
Let's discuss, wdyt
Beta Was this translation helpful? Give feedback.
All reactions