ES modules
ES modules were introduced as part of the ES2015 specification with the goal of giving JavaScript an official module system suitable for different execution environments. The ES modules specification tries to retain some good ideas from previous existing module systems like CommonJS and AMD. The syntax is very simple and compact. There is support for cyclic dependencies and the possibility to load modules asynchronously.
A cyclic dependency in a module system occurs when two or more modules depend on each other in a circular manner. For example, Module A imports from Module B, and Module B, in turn, imports from Module A. This creates a loop in dependencies that can lead to issues like incomplete module loading, runtime errors, or unexpected behavior, as the modules are unable to fully resolve due to their mutual reliance.
Using ES modules in Node.js
As previously discussed, when ES modules were introduced in Node.js, CommonJS had already long been...