
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
default-import
Advanced tools
Handle importing unknown/CJS modules in ESM that do not properly export a default value.
Importing CJS is supported natively in ESM, and the "default" import is the raw module.exports value. See NodeJS docs.
Some libraries improperly mix "default" and "named" exports in CommonJS, which requires extra instrumenting that is not natively available in ESM.
This library intends to provide the most basic instrumentation to properly access the default import.
npm i default-import
// a.cts
export default 123;
export const named = 456;
Compiles to
// a.cjs
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.named = void 0;
exports.default = 123;
exports.named = 456;
So importing doesn't work as expected!
// b.ts
import a from './a.cjs';
import { defaultImport } from 'default-import';
console.log(a);
// Expected: 123
// Actual: { __esModule: true, default: 123, named: 456 }
console.log(defaultImport(a)) // 123
default-import is an ESM module. That means it must be imported. To load from a CJS module, use dynamic import const { defaultImport } = await import('default-import');.
defaultImport() is idempotent and handles properly exported defaults so it is safe to use in environments that correctly provide default imports. That said, it is generally overkill and unnecessary to use this library in those cases.
It is best used when the runtime/source is not entirely in control, such as NextJS (ESM on server, "commonjs" on browser).
Extracts the proper default import from a CJS import.
Idempotent, and correctly handles proper default exports (e.g. default import from ESM .mjs file).
FAQs
Properly handle CJS imports in ESM.
We found that default-import 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.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.