Live data from Hacker News

CommonJS is hurting JavaScript

deno.com

11–20 of 134 posts

Re: CommonJS is hurting JavaScript

#12

Does anyone have a detailed understanding of why CommonJS (and its async incarnation, AMD) were not adopted by browsers? I do much like the `import` syntax personally and its a little cleaner to read, but CommonJS and AMD were the undisputed winners of the module format until ES Modules were born. Not that I have a problem with ES Modules, I don't, however I am interested in what was so insufficient about the precedi…

I don’t have an answer, and this is kind of superficial, but one thing I felt about the two was that import statements feel like compilation instructions. “Statically link this.” While Commonjs was a runtime function “synchronously acquire and parse this.”

I’m going to guess the good faith answer really involves some version of “CommonJS has some shortcomings and we didn’t want to confusingly write mostly-same syntax so we designed something new based on ideas from numerous languages.”

Re: CommonJS is hurting JavaScript

#13
post #2

[flagged]

It's almost a complete certainty that if Netscape used VBScript that the entire web browser concept would not exist due to legal action or being undermined technically. Don't you remember the dirty tricks they used with IE6? IE6 almost entirely cratered the web until MSFT unwittingly introduced XMLHttpRequest in an epic self-own.

In any case, WASM pretty much nullifies any problems with JavaScript going forward.

Re: CommonJS is hurting JavaScript

#15
the benefits of esm are not compelling enough to rewrite everything. Browser-native module loading is a niche use case which can never be as performant as bundling (even if per-request overhead is minimized in http2, a chain of dependencies will lead to excess round trips).

Re: CommonJS is hurting JavaScript

#16

Does anyone have a detailed understanding of why CommonJS (and its async incarnation, AMD) were not adopted by browsers? I do much like the `import` syntax personally and its a little cleaner to read, but CommonJS and AMD were the undisputed winners of the module format until ES Modules were born. Not that I have a problem with ES Modules, I don't, however I am interested in what was so insufficient about the precedi…

CommonJS requires invoking the code before the modules can be resolved, versus the ESModule syntax with "import" can be parsed out of the code separately (from the AST because it is a keyword). No invocation required.

I don't know if that's the entire story -- probably not -- but I do know that is one major differentiator for things like generating import-graphs and performing tree shaking.

(you can still do like `import('foo' + someVar)` which will only invoke dynamically at runtime, so I'm not sure how that case is dealt with)

Re: CommonJS is hurting JavaScript

#19
post #2

[flagged]

I agree that we should have another web programming option besides JavaScript.

However, the big boss still says "use JavaScript, period", and the tech economy dictates that supply side has the upper hand. The users are simple peasants who have no say in the matter. And frankly, none of them really care.

Unless Google execs start pushing an alternative on Chrome, we're stuck with what we have.

Post reply on HN