$ npm install @cspell/dynamic-import
@cspell/dynamic-importA small library to assist with dynamically loading CommonJS and ESM modules from either CommonJS or ESM modules.
npm install -S @cspell/dynamic-import
Example loading chalk v5, which is an ESM-only module.
TypeScript CommonJS
import { dynamicImport } from '@cspell/dynamic-import';
const pChalk = dynamicImport<typeof import('chalk')>('chalk', __dirname);
TypeScript ESM
import { dynamicImport } from '@cspell/dynamic-import';
const pChalk = dynamicImport<typeof import('chalk')>('chalk', import.meta.url);
TypeScript CommonJS
import { dynamicImport } from '@cspell/dynamic-import';
const pIndex = dynamicImport<typeof import('../esm/index.mjs')>('../esm/index.mjs', __dirname);
Brought to you by
Street Side Software
© 2010 - cnpmjs.org x YWFE | Home | YWFE