Live data from Hacker News

Node Modules at War: Why CommonJS and ES Modules Can’t Get Along

redfin.engineering

1–10 of 152 posts

Re: Node Modules at War: Why CommonJS and ES Modules Can’t Get Along

#3
Wow that was informative. So ES Modules is really about the Red functions [1] getting module support.

I find it fascinating watching our understanding of async computation mature over the years.

[1] http://journal.stuffwithstuff.com/2015/02/01/what-color-is-y...

Re: Node Modules at War: Why CommonJS and ES Modules Can’t Get Along

#5
I haven’t seen CommonJS modules for years now, only ES modules. Didn’t realize this was such an issue still.

> You can’t require() ESM scripts

That’s one way to put it! Another would be to say that you don’t have to. require() came about because we didn’t have the import keyword.

Re: Node Modules at War: Why CommonJS and ES Modules Can’t Get Along

#6

In two-and-a-half months the last 5 stable releases on Node, the last 2 LTS releases of Node, and all current major browsers will support standard JS modules. It's time we all published standard JS modules and only standard JS modules to npm.

> the last 2 LTS releases of Node

(Author here.)

Node 14 supports ESM, but Node 12 only supports ESM behind the --experimental-modules flag, and its error handling for incorrectly importing CJS is not good.

In 2020, I think it's a bit early to go ESM only, especially since it's straightforward for CJS libraries to support both CJS and ESM clients. (I document how to do this in the article.)

Re: Node Modules at War: Why CommonJS and ES Modules Can’t Get Along

#8
Enough with the hornet hate. They are great animals. If you know German, you can learn how great they are in the knowledge podcast of the Bavarian Broadcast: https://www.br.de/mediathek/podcast/radiowissen/die-wespe-un...

Or if you prefer this Hessian article:

https://www.faz.net/podcasts/wie-erklaere-ich-s-meinem-kind/...

Re: Node Modules at War: Why CommonJS and ES Modules Can’t Get Along

#10
JavaScript just gives to much options. I keep having problems with libraries because ES6 allows

  import x from "library";
  import {x} from "library";
  import * as x from "library";
  import {x as y} from "library";
Just to compare Java uses this:

  import java.lang.Double;
  import java.lang.*;
No renaming, not a gazillion options during in- and export, but one statement. If you want to rename something, assign it to a variable.

I don't understand why ES-module authors made it that complicated, when they had the chance to introduce a proper module system.

Why did they not just copy Java's system and be done with it.

Post reply on HN