
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
import-esm-interop
Advanced tools
A tiny wrapper around the dynamic import function for "requiring" ES modules in CJS code bundled by Webpack without triggering the ugly "critical dependency" warning
WTF is this?! Wow, well since I'm not giving up Jest anytime soon, this package is kinda useless until the segfault issue is resolved...
This package exposes a tiny Node.js-only wrapper around the import function.
This purpose of this wrapper is as syntactic sugar for dynamic imports of
externalized ESM dependencies in TypeScript/ESM
source destined to be bundled as CJS by Webpack. Since this package should
itself be an externalized dependency, using
import-esm-interop ensures:
Hence, this package has a very niche use case and you probably don't need it. For most packages, it's easier to use their CJS entry point if available. In a decade (🤞🏿) when CJS is dead and buried and ESM reigns supreme, this package will be deprecated.
This package also passes through TypeScript typings if provided.
npm install import-esm-interop
This interop function should only be used in CJS code or code that is compiled down to CJS (such as TypeScript)!
const { importEsm } = require('import-esm-interop');
// Equivalent to (await import('some-lib')).default
const someLib = await importEsm('some-lib');
// Equivalent to the above
const someLib = await importEsm('some-lib', 'default');
// Equivalent to the above, but with TypeScript typings
const someLib = await importEsm<import('some-lib').default>('some-lib');
// Equivalent to (await import('some-lib')).aNamedExport
const aNamedExport = await importEsm('some-lib', 'aNamedExport');
// Equivalent to { bNamedExport: (...).bNamedExport, cNamedExport: ... }
const { bNamedExport, cNamedExport } = await importEsm(
'some-lib',
'bNamedExport',
'cNamedExport'
);
// Equivalent to the above, but with TypeScript typings
const { bNamedExport, cNamedExport } = await importEsm<{
bNamedExport: import('some-lib').bNamedExport,
cNamedExport: import('some-lib').cNamedExport
}>('some-lib', 'bNamedExport', 'cNamedExport');
// Equivalent to await import('some-lib')
const SomeLib = await importEsm('some-lib', '*');
// Equivalent to the above, but with TypeScript typings
const SomeLib = await importEsm<import('some-lib')>('some-lib', '*');
If reusing the same typed import multiple times, you can make things less painful by extracting away the dynamic import into a top-level function. Said function could even be placed in a shared util file somewhere.
For example:
// file: ./vendor-interop.ts
export const importSomeLib = async () => {
return importEsm('some-lib', 'bNamedExport', 'cNamedExport') as {
bNamedExport: import('some-lib').bNamedExport,
cNamedExport: import('some-lib').cNamedExport
};
}
// file: ./index.ts
import { importSomeLib } from './vendor-interop'
export async function doesSomething() {
const { bNamedExport } = await importSomeLib();
bNamedExport();
}
Again, we use importEsm instead of inlining the dynamic import to avoid
problems with Webpack. If you're not bundling your source, then there is no
need to use this sugar function!
Further documentation can be found under
docs/.
This is a CJS2 package built for Node14 and above. Due to it
being for CJS<->ESM interop, this package is only available via require(...)
and cannot be imported by ESM code! Further, this package is not meant to be
bundled (and will likely cause an error if it is attempted), and should instead
be externalized along with every other module under
node_modules/.
For TypeScript and IDEs, each entry point (i.e. ENTRY) in package.json's
exports[ENTRY] object includes an
exports[ENTRY].types key pointing to its respective
TypeScript declarations file. There may be other keys for other
runtimes as well, including node and browser. Finally,
package.json also includes the
sideEffects key, which I set to false by default for
most of my libraries.
New issues and pull requests are always welcome and greatly appreciated! 🤩 Just as well, you can star 🌟 this project to let me know you found it useful! ✊🏿 Thank you!
See CONTRIBUTING.md and SUPPORT.md for more information.
FAQs
A tiny wrapper around the dynamic import function for "requiring" ES modules in CJS code bundled by Webpack without triggering the ugly "critical dependency" warning
The npm package import-esm-interop receives a total of 0 weekly downloads. As such, import-esm-interop popularity was classified as not popular.
We found that import-esm-interop demonstrated a not healthy version release cadence and project activity because the last version was released 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
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.