You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 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.
The text was updated successfully, but these errors were encountered:
We are not making the assumption that you're describing here. Are you saying that other people are making this incorrect assumption? Is there a question or a bug to report here?
node does not expose a module object in scope when it loads an ESM module, so the test in question is able to use the absence of module to reliably prove that the file was loaded as ESM instead of CommonJS, since we know within the scope of this test that a module object will not be coming from anywhere else.
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.
The text was updated successfully, but these errors were encountered: