2 ms·
> If we're ignoring edge cases ESM specifically doesn't ignore the edge case, it makes a special syntax for it! The point is that require() is surrounded by f
by afavour 3y ago
> If we're ignoring edge cases
ESM specifically doesn't ignore the edge case, it makes a special syntax for it!
The point is that require() is surrounded by footguns. It's a magic function with untold side effects. That's bad. If an inexperienced developer sees this:
const mod = require('module');
they might think it's fine to change it to:
const moduleName = 'module';
const mod = require(moduleName);
because why not? Or why not move it from the top level? There's nothing obvious about require() that would inform you you're about to cause a giant side effect. Indeed, on Node you wouldn't be. But you would be on a client-side build. This is the problem with non-standard implementations.
Switching from a top-level import to using import() has a drastic effect on your code: import() is async, requires you to wait on a promise to resolve, etc. etc. It's obvious that making the switch alters the structure of your code and the way it loads.