
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
module-compat
Advanced tools
Module type detection and loading for CJS and ESM compatibility.
npm install module-compat
import { moduleType, extToModuleType } from 'module-compat';
// Detect from file path (checks extension + package.json)
moduleType('/path/to/file.js'); // 'module' | 'commonjs'
// Detect from extension only (no filesystem access)
extToModuleType('.mjs'); // 'module'
extToModuleType('.cjs'); // 'commonjs'
extToModuleType('.js'); // undefined (need package.json check)
import { supportsESM, supportsSyncRequireESM } from 'module-compat';
supportsESM(); // true if Node 12+
supportsSyncRequireESM(); // true if Node 23+
import { loadModule, loadModuleSync } from 'module-compat';
// Callback-based (works on all Node versions)
loadModule('/path/to/module.mjs', (err, mod) => {
if (err) throw err;
console.log(mod);
});
// With options
loadModule('/path/to/module.mjs', { interop: 'raw' }, (err, mod) => {
// mod is the full namespace: { default, namedExport1, ... }
});
// Sync (CJS always works, ESM requires Node 23+)
const mod = loadModuleSync('/path/to/module.cjs');
Control how ESM default exports are handled:
| Mode | Behavior |
|---|---|
'default' | Extract .default if present (default) |
'raw' | Return module namespace as-is |
'typescript' | Check __esModule flag, then extract default |
// ESM module: export default fn; export function helper() {}
// interop: 'default' (default)
loadModule('module.mjs', (err, mod) => {
// mod = fn (the default export)
});
// interop: 'raw'
loadModule('module.mjs', { interop: 'raw' }, (err, mod) => {
// mod = { default: fn, helper: [Function] }
});
| Node Version | CJS | ESM (async) | ESM (sync) |
|---|---|---|---|
| < 12 | Yes | No | No |
| 12-22 | Yes | Yes | No |
| 23+ | Yes | Yes | Yes |
FAQs
Module type detection and loading for CJS and ESM compatibility
We found that module-compat demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.