模块路径或模块名
Optional
配置项
工作目录,默认为 process.cwd()
Promise<模块导出内容>
动态导入 ES 模块(异步)
// 导入本地 ES 模块const { default: config } = await importESM<{ default: Config }>('./config.mjs');// 导入 npm 包const { default: chalk } = await importESM<typeof import('chalk')>('chalk');// 指定工作目录const module = await importESM('./module.js', { cwd: '/custom/path' }); Copy
// 导入本地 ES 模块const { default: config } = await importESM<{ default: Config }>('./config.mjs');// 导入 npm 包const { default: chalk } = await importESM<typeof import('chalk')>('chalk');// 指定工作目录const module = await importESM('./module.js', { cwd: '/custom/path' });
模块路径或模块名