JS Utils Kit
    Preparing search index...

    Variable isCommonJSConst

    isCommonJS: boolean = ...

    Determines whether the current runtime is executing in a CommonJS environment.

    This performs multiple checks to improve reliability:

    • module.exports existence (primary CJS signal)
    • exports object presence
    • require function availability
    • __filename and __dirname variables

    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.

    if (isCommonJS) {
    console.log("Running in CommonJS");
    } else {
    console.log("Running in ESM");
    }