Security News
CISA Brings KEV Data to GitHub
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
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: I'll use pdfreader
package as example as this 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'
import type PdfReaderType from 'pdfreader'
async function loadPdf() {
const { PdfReader } = await importEsmModule<typeof PdfReaderType>( 'pdfreader' )
# your package is loaded, typed and ready to use :)
new PdfReader( ... )
}
If you're using Typescript, it's important to import add import type PackageType from 'mypackage'
so that intellisense will continue to work.
1.0.2 (2023-11-06)
Fixes on eslint Added error message if module load fails
FAQs
Loads ESM modules on CommonJS projects
The npm package commonjs-esm-loader receives a total of 139 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.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.