Hacker News new | ask | show | jobs
by reactus 1089 days ago
Would anyone be interested in an article about the crusade to move JS to ESM? I've been considering writing one, here's a preview:

Sindresorus wrote a gist "Pure ESM modules"[0] and converted all his modules to Pure ESM, breaking anyone who attempted to `require` the latest versions of his code; he later locked the thread to prevent people from complaining. node-fetch released a pure ESM version a year ago that is ~10x less popular than the CommonJS version[1]. The results of these changes broke a lot of code and resulted in many hours of developers figuring out how make their projects compatible with Pure ESM modules (or decide to ignore them and use old CommonJS versions)--not to mention the tons of pointless drama on GitHub issues.

Meanwhile, TC-39 member Matteo Collima advocated a moderate approach dependent on where your module will be run [2]. So the crusade is led not by the Church, but by a handful of zealots dedicated to establishing ESM supremacy for unclear reasons (note how Sindresorus' gist lacks any justifications and how weak TFA's justifications are). It's kind of like the Python 2 to 3 move except with even less rationale and not driven by the core devs.

0 - https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3...

1 - https://www.npmjs.com/package/node-fetch?activeTab=versions

2 - https://github.com/nodejs/node/issues/33954#issuecomment-924...

3 comments

ESM was a part of es2015. It's been 8 years that we've had to tangle with both cjs & esm. It's been absolutely awful for everyone.

This crusade is nowhere near zealous nor righteous enough against the infidels & non-believers.

But it also hasn't been effective enough at supporting/supplying the crusade either.

Matteo's statement was that Node hasn't stabilized their loader support so tools have a harm time migrating to esm. Imo it's a pity ecmascript never stabilized a module registry, that esm 1.0 shipped & most people thought it would happen; it's long felt like a bait & switch. But it wasn't a feature browsers needed or really wanted so that unfulfillment was unsurprising. Anyhow, IMO Matteo is making a technical point that it's still hard to finish the move, which is a different spin IMO than a "advocated a moderate approach".

Given the hurt we legitimately experience, I really wish Node and/or WinterCG or someone would prioritize figuring out & implementing whatever needs to go into a module registry/loader. And then beg the big tool chains that need this stuff to expedite their migrations, pretty pretty please.

> ESM was a part of es2015. It's been 8 years

Okay, but let's not resist inconveniencing ourselves with the facts.

ESM got browser support in 2017 and stable Node.js support in 2020.

> It's been absolutely awful for everyone.

It only became awful for me when people started publishing pure ESM packages; `npm i node-fetch` suddenly began resulting in broken scripts and I had to learn why. Prior to that, I happily used CJS outside of the browser and what I suppose is ESM in the browser (the `import` syntax provided by bundlers).

> a different spin IMO than a "advocated a moderate approach".

He said, "If your module target the Browser only, go for ESM. If your module target Node.js only, go for CJS."

This is moderate compared to the "Pure ESM" approach. The fetch API is built into browsers so I don't see why anyone would use `node-fetch` outside of Node.js, and yet the maintainers of `node-fetch` went Pure ESM anyway. Also that GitHub issue is titled "When will CommonJS modules (require) be deprecated and removed?" and his response was "There is no plan to deprecate CommonJS"[0].

0 - https://github.com/nodejs/node/issues/33954#issuecomment-776...

I mean, I took Sindre's move to ESM-only publishing as his own choice as the author and maintainer of his own OSS packages. In the spirit of OSS, he doesn't need to justify the choice, it's good enough that as the author he's making it. The previous CJS versions are still published, and anyone can fork the modules if they want to take on the maintenance burden of the CJS version.

That preference has had an impact on the Node ecosystem at large, given how prolific an OSS contributor Sindre is, but IMO that influence has been earned by the large body of work he's contributed.

And yet his older CJS versions get weekly downloads that are magnitudes higher than the newer ESM versions.

I'm working on greenfield projects that leadership is still insisting we avoid ESM-only packages for. The move that Sindre (and others like wooorm) made has not been well-received.

> And yet his older CJS versions get weekly downloads that are magnitudes higher than the newer ESM versions.

You write this as if that mattered...

Should he only works on stuff that gets more download? For what reasons? He works on what he wants to works on, it's amazing and he is lucky to be able to do it.

> The move that Sindre (and others like wooorm) made has not been well-received

It's normal to be sad to have lost someone that was working on something you needed, but anything else is just entitlement.

> You write this as if that mattered... Should he only works on stuff that gets more download?

It was a statement of fact. You appear to be drawing conclusions that were never hinted at nor implied. It's tiresome.

> It's normal to be sad to have lost someone that was working on something you needed, but anything else is just entitlement.

How and why are you applying entitlement and emotion to a documented statement of fact? Do you need to see links such as [1] to view that as fact? It's one of a myriad. Take your asinine analysis and commentary elsewhere, please.

[1] https://github.com/sindresorhus/meta/discussions/15

Many authors don't care if 5 dudes use their stuff, or the rest of the world, specially when taking zero monetary value out of it.
I'm one of them, as I'm a prolific open source contributor and maintainer. To argue that some high-profile authors don't get any monetary value from their public work is to be simply naive and uninformed. The two I mentioned have made careers on that work and derive the majority of their income from it.
OK so anyone disagreeing via their clicks on the down button, please provide a rebuttal. Have yet to see one.
This is irresponsible approach and this package should be forked by more responsible people. Person who made this change should be avoided in the future.

I'm all for ESM but alienating your own users is stupid. Create node-fetch-esm and support both versions until commonjs popularity would be low enough to be dropped.