Const
Determines whether the current runtime is executing in a CommonJS environment.
This performs multiple checks to improve reliability:
module.exports
exports
require
__filename
__dirname
No single check is fully reliable across all bundlers/transpilers, so a combination is used.
true if the runtime is very likely CommonJS, otherwise false.
true
false
if (isCommonJS) { console.log("Running in CommonJS");} else { console.log("Running in ESM");} Copy
if (isCommonJS) { console.log("Running in CommonJS");} else { console.log("Running in ESM");}
Determines whether the current runtime is executing in a CommonJS environment.