I saw a merge with a test like
// Test import builtin modulesimport{readFileSync}from'fs';if(typeofreadFileSync!=='function')thrownewError('failed to import builtin module')if(typeofmodule!=='undefined')thrownewError('module should not exist in ESM')And i see no problem with that test at all it is from #1136
but i need to make sure that you no where see that as general rule of thumb module and module.exports do exists inside ESM
here a example CJS loader written in ESM to load CJS inside a browser via esm
asyncfunctionrequire(path){let_module=window.module;window.module={};awaitimport(path);letexports=module.exports;window.module=_module;// restore globalreturnexports;}(async()=>{// top-level await cannot come soon enough…letx=awaitrequire("https://cdn.jsdelivr.net/gh/x/lib/index.js");})();in nodejs we have directly
import{createRequire}from'module';it is importent that you understand that ESM includes everything CJS includes + ESM every node builtin module exists only as CJS version and gets a additional wrapper to be ESM Compatible.
I saw a merge with a test like
And i see no problem with that test at all it is from #1136
but i need to make sure that you no where see that as general rule of thumb module and module.exports do exists inside ESM
here a example CJS loader written in ESM to load CJS inside a browser via esm
in nodejs we have directly
it is importent that you understand that ESM includes everything CJS includes + ESM every node builtin module exists only as CJS version and gets a additional wrapper to be ESM Compatible.