+In ESM, too, every file is a module with its own scope and context. One major advantage in ESM over CJS is how ESM has -- and encourages -- a way of statically importing dependencies. Static imports vastly improve the introspection capabilities of module systems, given they can be analyzed statically and lexically extracted from the abstract syntax tree (AST) of each module in the system. Static imports in ESM are constrained to the topmost level of a module, further simplifying parsing and introspection. Another advantage of ESM over CommonJS `require()` is that ESM specifies a way of doing asynchronous module loading, which implies that parts of an application's dependency graph could be loaded in response to specific events, concurrently, or lazily as needed. Although this feature is not yet implemented in most environments at the time of this writing, there is strong indicationfootnoteref:[esm-node,You can dive into the specifics through this article from a member of the Node.js team, Myles Borins: https://mjavascript.com/out/esm-node.] that Node.js would incorporate it in the future.
0 commit comments