This is not meant to be a comprehensive overview of ES modules and CommonJS modules — I do not go into depth about what modules are and how they work. Rather, it is meant to highlight the differences between ES modules and CommonJS modules and how you can use them together.
This is part one of a four part series.
- Using ES modules using CommonJS modules in Node.js
- Using ES modules using CommonJS modules in the browser
- Using ES modules using CommonJS modules with webpack
Mixing ES modules and CommonJS modules
This topic is a bit misleading, because the browser doesn’t have built-in support for CommonJS modules. That is, there is no built-in
require function, and there is no global
exports object that you can add exported variables and functions to.
So, without using any additional libraries, the compatibility chart looks like this: