Replies: 3 comments 3 replies
-
ESM is a standard, cjs isn't. That is mostly it. If we could influence more ppl to switch to writing ESM instead of cjs then that would mean that more code would also be more cross compatible with Deno and also browsers. Writing things as a ESM also allows for HTTP import without the need for local package manager where only NPM has the monopoly. ESM have other features that cjs do not such as top level await ESM is going to be the new facto way of writing modules in the feature. So it's just about sucking it in and start emprising it. The newer updated nodejs docs also shows ESM flavored syntax now. Now i know node-fetch is written exclusively for NodeJS programs only so it could as well have been written in cjs flavored syntax but we wanted to embrace standards, work with web standards and not have to deal with down leveling from esm to cjs with build tools such as babel or rollup. we felt that a dual package with both cjs & esm support was a hazard. and it is: https://nodejs.org/dist/latest-v18.x/docs/api/packages.html#dual-package-hazard We spoke about making the switch to ESM for a long time before making the switch and everyone involved in node-fetch was onboard with it at the time and nobody was against it when we decided to write it as ESM and starting to ditch babel. it wasn't singly one sided goal cuz everything we do here is being reviewed by other members before being merged. and you can't review/accept your own PRs. |
Beta Was this translation helpful? Give feedback.
-
Also want to point out that you do not have to rewrite everything into ESM, you can still load ESM modules from cjs using async import (due to its nature of how esm modules are loaded) // index.cjs
import('node-fetch').then(...) alternative you could just update to newer NodeJS version (18+) that now has fetch built in. |
Beta Was this translation helpful? Give feedback.
-
Strong doubt you "code" in CJS, chances are you are writing "ESM" (syntactically invalid ESM, but it's okay because the transpiler will gobble it up anyway) code and CJS is merely an implementation detail of the build step. Kinda strange to expect a package implementing one of the ECMAScript spec features not to eventually follow the module system of ECMAScript. |
Beta Was this translation helpful? Give feedback.
-
Looking around the issues and discussions, I see none that seem to tackle the question, if there are I'll gladly look into them.
So, why? Why the switch to ESM when ESM is backwards compatible? Using CJS would have been painless for people who code in CJS. I might find myself rewriting all of my code because it is recommended to switch to ESM.
Moreover, this doesn't seem to affect ESM users positively, if at all.
So yeah, why did the switch happen?
I'm sorry if the message might sound arrogant or unthoughtful, it has been lingering in my mind for a bit now, but I truly want to understand.
Beta Was this translation helpful? Give feedback.
All reactions