When building JavaScript for Node.js, bundles must be made available in the CommonJS format. As of Node 12, ECMAScript Modules are also supported alongside CommonJS, with the appropriate format being selected based on Export Maps. Code destined for Node should be packaged in both formats to provide flexibility and version compatibility.
If you're targeting modern browsers, ECMAScript Modules are best, however older browsers may not support it. Even in newer browsers, support for modules isn't available in some contexts: Web Workers only support modules in Chrome, and no browsers support modules in service workers. In these cases, a custom module format implementation must be used to ensure browser support.