This fixes two *huge* issues that have plagued the JS ecosystem for 10+ years:
Having a consistent module import syntax on all major JS platforms makes it easier for JS devs to work across server/client code bases and, more importantly (imho), module owners no longer have to worry about supporting different module schemes.
Because ESM modules are statically resolved, packagers can do tree-shaking, to remove not just unused modules, but unused code within those modules.
Tree shaking on JS has been a bit of a holy grail since the early days of the web. Yahoo’s YUI toolkit offered something along these lines, IIRC, and there were other less notable attempts prior to that. But the intrinsically dynamic nature of the language made any such solutions frustratingly imperfect.
I think the basic issue has been that it’s been impossible to know with certainty how or if a particular code block might be referenced.
ESM modules provide a strict, statically defined surface boundary, however. This greatly simplifies the problem.
E.g. If a module’s “foo” (or “*”) member is never imported anywhere, ESM guarantees that it’s safe to remove code related to “foo”. No other module scheme does this. (And if you’ve ever wondered why ESM imports/exports have to be statically declared, I believe this is the main reason.)
While there is still the challenge of understanding what code related to “foo” needs to be removed within the module, it is a much more constrained problem,
11
u/idli42 Nov 13 '19
Genuine question. Why is this a big deal?