Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Maybe npm module with dynamic import is not included in binary #1828

Closed
kochizufan opened this issue Dec 19, 2022 · 4 comments
Closed

Maybe npm module with dynamic import is not included in binary #1828

kochizufan opened this issue Dec 19, 2022 · 4 comments
Labels

Comments

@kochizufan
Copy link

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
  1. Add this to package.json
  "pkg": {
    "assets": ["node_modules/flatgeobuf/**/*"]
  },
  1. Create src/test.js with this content:
const main = async () => {
  const { geojson } = await import("flatgeobuf");
  console.log("It works!");
};

main();
  1. Compile
pkg src/test.js --target=node16-win-x64 --output=dist/test.exe
  1. Executing dist/test.exe causes 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
  1. Comment out dynamic import:
const main = async () => {
  // const { geojson } = await import("flatgeobuf");
  console.log("It works!");
};

main();
  1. Compile
pkg src/test.js --target=node16-win-x64 --output=dist/test.exe
  1. Executing dist/test.exe:
It works!
@albertininm
Copy link

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?

@robertsLando
Copy link
Contributor

Here a hint about how to fix that: #1419 (comment)

@github-actions
Copy link

github-actions bot commented May 3, 2023

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

@github-actions github-actions bot added the Stale label May 3, 2023
@github-actions
Copy link

github-actions bot commented May 8, 2023

This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.

@github-actions github-actions bot closed this as completed May 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants