动态导入 - import() - 将代码打包为可执行文件时失败
Dynamic import - import() - fails when the code is packaged into an executable
我在 commonjs
环境中工作,试图动态导入 es
模块
考虑以下代码:
const mysqlController = (async function () {
try{
var {default:dateformat}= await import('dateformat');
// also tried await import('../../../node_modules/dateformat/lib/dateformat.mjs')
}
catch(e){
console.error('Line 31 of db_controller');
console.error(e);
}
// More stuff
})()
语句await import('dateformat');
在调试时工作正常。但是当使用 pkg
生成独立的可执行文件时,会出现以下错误:
TypeError: Invalid host defined options
有人能告诉我这是怎么回事吗?
我在 commonjs
环境中工作,试图动态导入 es
模块
考虑以下代码:
const mysqlController = (async function () {
try{
var {default:dateformat}= await import('dateformat');
// also tried await import('../../../node_modules/dateformat/lib/dateformat.mjs')
}
catch(e){
console.error('Line 31 of db_controller');
console.error(e);
}
// More stuff
})()
语句await import('dateformat');
在调试时工作正常。但是当使用 pkg
生成独立的可执行文件时,会出现以下错误:
TypeError: Invalid host defined options
有人能告诉我这是怎么回事吗?