Maybe npm module with dynamic import is not included in binary
What version of pkg are you using?
5.8.0
What version of Node.js are you using?
16.18.1
What operating system are you using?
Windows
What CPU architecture are you using?
x86_64
What Node versions, OSs and CPU architectures are you building for?
node16-win-x64
Describe the Bug
In my app, I import the npm module dynamically like:
const main = async () => {
const { geojson } = await import("flatgeobuf");
console.log("It works!");
};
main();
But this causes error when I run the app of compiled result.
pkg/prelude/bootstrap.js:1930
return wrapper.apply(this.exports, args);
^
TypeError: Invalid host defined options
at main (C:\snapshot\src\test.js)
at Object.<anonymous> (C:\snapshot\src\test.js)
at Module._compile (pkg/prelude/bootstrap.js:1930:22)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.runMain (pkg/prelude/bootstrap.js:1983:12)
at node:internal/main/run_main_module:17:47
Once I commented out this dynamic import, app works well. No error.
So I dought compiled image not included target module.
I'm sure to add
"pkg": {
"assets": ["node_modules/flatgeobuf/**/*"]
},
to my package.json, but there are no changes.
Expected Behavior
Successfully run without error.
To Reproduce
$ npm install flatgeobuf
- Add this to package.json
"pkg": {
"assets": ["node_modules/flatgeobuf/**/*"]
},
- Create src/test.js with this content:
const main = async () => {
const { geojson } = await import("flatgeobuf");
console.log("It works!");
};
main();
- Compile
pkg src/test.js --target=node16-win-x64 --output=dist/test.exe
- Executing
dist/test.execauses error:
pkg/prelude/bootstrap.js:1930
return wrapper.apply(this.exports, args);
^
TypeError: Invalid host defined options
at main (C:\snapshot\src\test.js)
at Object.<anonymous> (C:\snapshot\src\test.js)
at Module._compile (pkg/prelude/bootstrap.js:1930:22)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.runMain (pkg/prelude/bootstrap.js:1983:12)
at node:internal/main/run_main_module:17:47
- Comment out dynamic import:
const main = async () => {
// const { geojson } = await import("flatgeobuf");
console.log("It works!");
};
main();
- Compile
pkg src/test.js --target=node16-win-x64 --output=dist/test.exe
- Executing
dist/test.exe:
It works!
I have the same problem with the usage of pMap, which also requires dynamic imports. @kochizufan did you find a workaround for this issue meanwhile?
Here a hint about how to fix that: https://github.com/vercel/pkg/issues/1419#issuecomment-997982346
This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label
This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.