3 ms·
> many people have transpilers configured wrong ? It's so that CommonJS modules can use ESM modules. --- Like suppose examplelib uses otherlib, both in Comm
by paulddraper 3y ago
> many people have transpilers configured wrong
?
It's so that CommonJS modules can use ESM modules.
---
Like suppose examplelib uses otherlib, both in CommonJS.
The examplelib wants to upgrade otherlib, but the new version uses ESM. Now, examplelib is stuck either on the old version, or has to undertake a rewrite (and propagate this situation downstream). Or adopt a transpiler and force downstream users to do the same.
Some would say "just rewrite in ESM" and that is a nice idea, but there are lots of tools with caveats, TypeScript, Jest, anything that depends on require-in-the-middle, etc.
It's hard to boil the ocean. (Just look at Python 3.)
- WorldMaker 3y agoCommonJS modules (and anybody else that prefers or needs "require-in-the-middle") can already import ESM. They need to use `await import()` or `import().then()` if they prefer callback waterfalls to async/await syntax. That works everywhere in Node today. Sure, it's a pain when upstream switches to ESM that you have to use more Promises, but that the price you pay and it is certainly a lot less work than a full rewrite even for the most brownfield CommonJS library. You don't have to rewrite everything to ESM all at once. (You should want to, but don't have to.)
- paulddraper 3y agoExchanging one function coloring problem for another isn't what I would call "less work."