by desmap · 6y ago · 0 comments
OP wrote, note that it’s easy to write an ESM wrapper for CJS libraries, but it’s not possible to write a CJS wrapper for ESM libraries.
You can - and people widely do - compile a CJS version of your library from ESM sources. You'll accept that there may be multiple copies of your library in the program but it does work. But in any case there's no reason to actually author in CJS, everything including the ESM shim can be generated from ESM.
A library author can provide cjs bindings to their library for as long as cjs remains relevant with the assumption that they won't use top level await.
Last time I checked they seemed to lean into using rollup to take care of the translation under the covers.
From what I have seen seems pretty typical to simply export the named properties using a fresh module.exports = {...} and then use default as the main export?