CommonJS versus ES Modules

Created: Jul 18 2025, 13:54 UTC
Last modified: Jul 18 2025, 13:54 UTC

These are competing Javascript module systems.

In the beginning there was CommonJS. This is the old, familiar module system that they used on Node. You recognize it by the all the require calls at the top of your file and the module.exports section at the bottom.

ES(6?) modules are the newer Javascript standard. They are supported in Node past version 8, but not by default. You have to turn them on by either:

  • Using an *.mjs extension or
  • Using type: module in your package.json.

Pretty simple, actually. It’s when you add Typescript to the mix that things get super hairy.

No backlinks