3 ms·
Sometimes I feel like I am the only human on Earth who likes ES Modules end to end, 100 %. Ecosystem divide? What would be the point of ESM if it did not do th
by tomashubelbauer 3y ago
Sometimes I feel like I am the only human on Earth who likes ES Modules end to end, 100 %.
Ecosystem divide? What would be the point of ESM if it did not do this? We could have kept using `require`s if the bar is that the new, language-native module system must not cause any sort of a transition period where people adopt it and displaces the previous ad-hoc (IMO anti-) patterns that were used for "modules" before ESM.
Doesn't work everywhere yet? The support is growing and developers IMO should learn about and default to ESM. That's how the support and availability of packages will continue to grow to eventually 99.9 displace previous methods.
> And then there's Rollup, which apparently requires ESM to be used, at least to get things like treeshaking. Which then makes people believe that treeshaking is not possible with CommonJS modules.
I am not convinced the people referred to here are real humans and not made up to support the author's argument.
Babel's problems are Babel's problems, ESM is not the cause of the problem here.
> ESM in browsers without a build step!", apparently not realizing that that is an utterly useless feature
A hands down amazing feature, something I was pining for for so long and it is finally here. Performance? Sure, if you are building high traffic sites, you will still reach for a bundler, but browser ESM without a build step will allow many intranet and low traffic Internet development teams to ship much nicer code than they do now after buying into bundle-everytime voodoo. If this existed before WebPack, so much spaghetti code could have been avoided.
The point of static analysis I can't comment on as I have never authored any tools for static analysis of JavaScript codebases using modules, but if I were to, I would be very happy to have an actual language feature for modules with a spec at hand rather than a bunch of IMO ugly patterns that only existed out of necessity because the module system at language level took long to arrive.
> CommonJS is so ubiquitous in Javascript-land nowadays that it will never fully go away
Unfortunately true, but that doesn't mean we shouldn't strive for something better. I know the author used the word standard and it can be interpreted many ways, but ESM is IMO better because it is a feature of the language, not the ecosystem.
> The vast majority of people who believe they're currently using ESM, aren't even actually doing so - they're feeding their entire codebase through Babel, which deftly converts all of those snazzy import and export statements back into CommonJS syntax.
But browsers supporting ESM directly is somehow a problem? It's better to rely on bundlers for everything even at the cost of them doing stupid shit like this by default? Not to mention this is completely configurable and avoidable with minimal amount of effort.
> the following pattern is simply not possible with ESM
That's a good riddance from me! ESM being statement keywords and not expression keywords (aside from dynamic imports) is IMO the right choice.
> do you want to be able to use ESM-only dependencies
Yes, please.
> You've destroyed a successful userland specification
I am happy to have contributed to proliferation of a successful kernel specification if we're sticking with this metaphor.
- TheAceOfHearts 3y ago> A hands down amazing feature, something I was pining for for so long and it is finally here. Performance? Sure, if you are building high traffic sites, you will still reach for a bundler, but browser ESM without a build step will allow many intranet and low traffic Internet development teams to ship much nicer code than they do now after buying into bundle-everytime voodoo. If this existed before WebPack, so much spaghetti code could have been avoided. Before or around the same time CommonJS appeared there was another module system before Webpack existed, I think it was called Async JS. It was browser-first and allowed you to do JS development in the manner which you describe. It was also supported by Webpack's bundler. A bit surprising to see this piece of history getting memory holed. Edit: I think it was called RequireJS? You would give it an array of dependency paths and a callback function to get executed once everything was loaded.
- tomashubelbauer 3y agoI have not heard of it but I think the main benefit of ESM over a bunch of `script` tags (what I used before CJS came about) is that the individual modules files are isolated and do not share globals which was a common pain point when using `script` tag soup and something that IMO drove a lot of people to use bundlers to avoid this who did not benefit from bundling otherwise (intranet web apps and low traffic Internet apps - their debugability went downhill and stayed there for a long time and even with the introduction of source maps and such, those weren't supported right away in all tooling). If the thing you describe solved this back then I regret not having come across it.
- TheAceOfHearts 3y agoIt's been a really long time since I last used this tool, but I think it always executed asynchronously within a callback function. So doing stuff like `var foo` wouldn't affect the global scope, since your code was always supposed to be placed inside a function call which receives all dependencies as a parameter. https://requirejs.org/docs/api.html https://requirejs.org/docs/api.html
- 3y ago