【发布时间】:2023-01-29 01:59:14
【问题描述】:
我创建了一个命令行包,在其代码中动态加载了包。
如何在代码中安装动态包?
例子:
hello-so包裹
export default async function() {
const ex = await import(process.argv[2]);
const raw = await ex.default(process.argv[3]);
}
hello-so-module包裹
export default async function(hello) {
console.log(hello);
return hello;
}
跑步:
npx hello-so "hello-so-module" "Hello stackoverflow"
会报错,因为没有安装hello-so-module包。但是如何在代码中安装它,或者还有其他选择?
我认为用户必须全局安装动态模块。
【问题讨论】: