Skip to content

Instantly share code, notes, and snippets.

@ganeshkbhat
Last active October 30, 2022 02:51
Show Gist options
  • Save ganeshkbhat/039f601b72f650535bc44502bda4c38c to your computer and use it in GitHub Desktop.
Save ganeshkbhat/039f601b72f650535bc44502bda4c38c to your computer and use it in GitHub Desktop.
Find if a code is a ESM Module or a CommonJS Script or Module
const checkEsm = import("check-esm");
let isesm = checkEsm._isESCode("./isESCode.mjs");
console.log(isesm);
const checkEsm = require("check-esm");
let isesm = checkEsm._isESCode("./isESCode.cjs");
console.log(isesm);
import { _isESCode } from "check-esm";
let isesm = _isESCode("./isESCode.js");
console.log(isesm);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment