
Product
A Fresh Look for the Socket Dashboard
We’ve redesigned the Socket dashboard with simpler navigation, less visual clutter, and a cleaner UI that highlights what really matters.
load-esm is a utility for dynamically importing pure ESM (ECMAScript Module) packages in CommonJS TypeScript projects. This is particularly useful when working with Node.js environments configured for CommonJS while needing to integrate ESM-only dependencies.
npm install load-esm
or
yarn add load-esm
Here’s an example demonstrating how to use load-esm to dynamically load an ESM module in a CommonJS project:
import * as path from 'path';
import { loadEsm } from 'load-esm';
/**
* Import 'file-type' ES-Module in CommonJS Node.js module
*/
(async () => {
try {
// Dynamically import the ESM module
const { fileTypeFromFile } = await loadEsm('file-type');
// Use the imported function
const type = await fileTypeFromFile('fixture.gif');
console.log(type);
} catch (error) {
console.error('Error importing module:', error);
}
})();
loadEsm<T = any>(name: string): Promise<T>
Dynamically imports an ESM module.
name
(string): The name or path of the module to load.Promise<T>
that resolves to the imported module object.import { loadEsm } from 'load-esm';
(async () => {
const module = await loadEsm('some-esm-module');
console.log(module);
})();
The utility leverages Node.js's import() function to dynamically load ESM modules. This allows CommonJS-based projects to interact with ESM dependencies without converting the entire project to ESM.
In mixed-module environments where your project is primarily CommonJS but relies on some ESM-only dependencies, load-esm serves as a seamless bridge, enabling interoperability without changing your project’s module system.
FAQs
Utility to dynamically load ESM modules in TypeScript CommonJS projects
The npm package load-esm receives a total of 1,319,574 weekly downloads. As such, load-esm popularity was classified as popular.
We found that load-esm demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Product
We’ve redesigned the Socket dashboard with simpler navigation, less visual clutter, and a cleaner UI that highlights what really matters.
Industry Insights
Terry O’Daniel, Head of Security at Amplitude, shares insights on building high-impact security teams, aligning with engineering, and why AI gives defenders a fighting chance.
Security News
MCP spec updated with structured tool output, stronger OAuth 2.1 security, resource indicators, and protocol cleanups for safer, more reliable AI workflows.