Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Maybe the right way to think about it is that ESM is python3 for the javascript world. If javascript had ESM from the start, it would be fine. And maybe once every package in npm is rewritten for ESM, it'll be fine. But in the meantime, we have essentially 2 mutually (sort of) incompatible programming languages which share a name and a package repository.

> You see, it's not that ESM killed JavaScript, all the hacky build tools did.

The problem is that ESM added a massive extra amount of complexity to all those hacky build tools, because suddenly we have 2 different kinds of javascript code and people expect their code to be mutually compatible. That is really complex.

- Typescript's canonical way to import things (import foo from './blah') is incompatible with ESM imports (because imports must have file extensions).

- Nodejs has a plethora of options to configure packages to support combinations of ESM and CJS[1]. Half of those options are deprecated. Lots of tools read package.json - but don't parse all those different options consistently with nodejs's implementation.

- Eg: wasm-pack only knows how to compile code "for the web" or "for nodejs". (You want a package that works everywhere? Adorable.) The web version creates an ESM module, but doesn't specify "type": "module" in package.json - so even though it could work with nodejs, it doesn't.

- Lots of packages in npm are broken in either CJS or ESM mode. And there's no way to tell without trying them.

Essentially, we went from having a simple, extensible system (commonjs + bundlers) to a very complex system. The number of people who understand all that complexity has dropped by orders of magnitude. Now I feel less capable of creating working code than I was a few years ago.

Its an unmitigated disaster for the ecosystem. Maybe in a few years, everything will be using ESM. But until then, I want off this ship.

[1] https://nodejs.org/dist/latest-v18.x/docs/api/packages.html#...



We’re saying the same thing:

> Lots of packages in npm are broken in either CJS or ESM mode. And there's no way to tell without trying them.

I blame npm for allowing that to happen. I get that it’s technically a third party, but they never even checked that the file mentioned in `main` was included, even without a “postinstall” step.

They, together with node, could have built a tool that validates main/type/exports on publish, but no. There’s literally no way to validate ESM until you run them or use a full linter. The whole point of ESM was that it’s statically analyzable.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: