
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
commonjs-esm-loader
Advanced tools
Trying to load a fresh installed package and got the error cannot use import statement outside a module
? This packaged is the sollution for your problems.
I've created it after Googling a lot trying to find a sollution on how to import an ESM package in a big and consolidated CommonJS project... Migrate whole project to ESM architecture just to use a single package was not an option.
Is this package usefull to you? Support it buying me a coffee ☕ or giving a ⭐ on GitHub.
To install, you can use npm or yarn:
npm install commonjs-esm-loader
# or
yarn add commonjs-esm-loader
OBS: Using pdfreader
package as example because it was the package that makes me create this project, but it works with any ESM package you want to load.
import { importEsmModule } from 'commonjs-esm-loader'
async function myFunction() {
const { PdfReader } = await importEsmModule( 'pdfreader' )
// your package is loaded and ready to use :)
new PdfReader( ... )
}
import { importEsmModule } from 'commonjs-esm-loader'
// load package type so intellisense can work
import type PdfReaderType from 'pdfreader'
async function myFunction() {
const { PdfReader } = await importEsmModule<typeof PdfReaderType>( 'pdfreader' )
// your package is loaded, typed and ready to use :)
new PdfReader( ... )
}
FAQs
Loads ESM modules on CommonJS projects
The npm package commonjs-esm-loader receives a total of 454 weekly downloads. As such, commonjs-esm-loader popularity was classified as not popular.
We found that commonjs-esm-loader 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
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.