3 ms·
> ESM modules are challenging to mock > I definitely would say I understood require better ESM modules are in many ways "harder" to use than commonjs, but I t
by lucideer 5y ago
> ESM modules are challenging to mock
> I definitely would say I understood require better
ESM modules are in many ways "harder" to use than commonjs, but I think this comes down to something slightly intangible but very similar to the static-typing -vs- duck-typing discussion (duck-typing is more obviously intuitive and quick-to-do-what-you want, but static-typing has more wide-reaching architectural benefits for scaling projects).
CommonJS is a more "intuitive" design: what you might expect someone to design first-time-around. ESM is a more thought-through design: the initial "hurdles" to its use bring long-term benefits.
> ESM modules are challenging to [...] monkeypatch
This seems like a feature though
> I feel like the ESM implementation is more "magic" than require
How so? I'd say I feel the opposite.
> importing a .json file
Is this supported by browsers or is it a NodeJS extension?
- lucacasonato 5y ago> Is this supported by browsers or is it a NodeJS extension? This is a node extension. It is coming to browsers in form of import assertions. See https://github.com/tc39/proposal-import-assertions https://github.com/tc39/proposal-import-assertions
- lucideer 5y agoOh, good to know! I hadn't heard this. Just for anyone tracking progress, the actual feature proposal is here: https://github.com/tc39/proposal-json-modules https://github.com/tc39/proposal-json-modules - the assertions proposal is just a security check on top of such modules.