jargon

Comparison

CommonJSvsES module

CommonJS

the package only shipped `require` and your bundler could not shake anything out of it.

Node's original module format, where `require` is a function call that runs at execution time and `module.exports` can be reassigned conditionally. Because the exports are only known by running the code, bundlers must include the whole module, so a CommonJS-only dependency defeats tree shaking. The mismatch between the two formats is behind most 'cannot use import statement outside a module' and default-interop errors.

Full entry →

ES module

you wrote `import` at the top of the file and the tooling could tell what you used without running anything.

The standard module format, with static `import` and `export` declarations that can be analysed without executing the file. That static shape is what makes tree shaking possible at all, and it is why dynamic imports are the only conditional form allowed. Modules are strict mode, deferred, and evaluated once, which is why a module-level variable is a singleton whether you meant it to be or not.

Full entry →

Related comparisons