Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
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.
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 182 weekly downloads. As such, commonjs-esm-loader popularity was classified as not popular.
We found that commonjs-esm-loader 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.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.