Skip to content

fix: ES build

Anton requested to merge (removed):fix-es-build into master

This PR makes the ES build compatible with the Node ES module spec, and closes #124 (closed)

The main barrier to making this possible, is that this program uses a lot of dynamic require() calls, and to properly comply with the ES spec, those should be replaced with dynamic import() calls. That's hard to do because import() calls are asynchronous, so it won't be possible to do this until you make the entire API async (a massive breaking change).

As a temporary fix to this problem, I have re-imported the old require() functions into the ES modules and called them legacyRequire().

One of the downsides of the temporary fix, is that configuration files can't be ES modules, they have to stay as CommonJS modules for now. To help alleviate that problem, I have added support for .cjs files, which is a convenient way of letting Node know that it should interpret the file as a CommonJS module, even though the rest of the program is ESM.

Merge request reports