ESM vs CJS #279
Replies: 4 comments 11 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.
-
|
We get more frequent issues with ESM related dependencies in our toolchain and I think we should now make an official transition Date, for example by the end of 2026 this project is ESM only. At the same time we should think about some dependencies that are getting really annoying, for example eslint which is basically useless since version 9. A great alternative would be biome as it includes linter and formatter and could be a great help during our transition to full ESM. Please let me know what you think about this transition phase: #384 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
UPDATE December 2025
We will have to move to ESM and there is no way back. Please vote for an eol of the CJS version here: Please vote for an CJS eol here: #384
Original Discussion
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