yao-pkg / pkg

Package your Node.js project into an executable
https://www.npmjs.com/package/@yao-pkg/pkg
MIT License
395 stars 19 forks source link

Library not loaded: @loader_path/libpixman-1.0.42.2.dylib #71

Closed winjeysong closed 5 months ago

winjeysong commented 5 months ago

What version of pkg are you using?

5.12.0

What version of Node.js are you using?

18.0.0

What operating system are you using?

macOS

What CPU architecture are you using?

Apple M1

What Node versions, OSs and CPU architectures are you building for?

node18-macos-x64

Describe the Bug

Thanks for maintaining this project! I got a problem when making executable with canvas:

I found a related issue: https://github.com/vercel/pkg/issues/1135, but it seems still not fixed on macos...

Expected Behavior

make executable with canvas

To Reproduce

reproduce repo here: https://github.com/winjeysong/pkg-canvas-test. after cloning, run scripts below and you will see the error message I've mentioned above.

pnpm i
pnpm make-bin
pnpm run-bin
robertsLando commented 5 months ago

add missing lib to assets

winjeysong commented 5 months ago

assets already set in package.json, but useless... 😭

robertsLando commented 5 months ago

Try with node_modules/canvas/**/*

winjeysong commented 5 months ago

Try with node_modules/canvas/**/*

still error... It seems pkg only copies canvas.node to cache dir, but ignores all other .dylib files

robertsLando commented 5 months ago

The code that handles the copy of that folder is this: https://github.com/yao-pkg/pkg/blob/main/prelude/bootstrap.js#L2199

Try to debug it yourself (maybe better if you create a minimal repo that only imports canvas) and then open a PR

You can also try to package your applicaiton with --debug flag and then run it with DEBUG_PKG=2 env var to see what's inside the snapshot. See docs here: https://github.com/yao-pkg/pkg?tab=readme-ov-file#debug

winjeysong commented 5 months ago

Thank you for your rapid response. I'm debugging now, and I'll open a PR asap.

winjeysong commented 5 months ago

After debugging, I find that running pkg src/index.js --output dist/bin --targets node18-macos-x64 --compress GZip will not include packageJSON.pkg config. And I reread the doc carefully, It says:

Just be sure to call pkg package.json or pkg . to make use of package.json configuration.

I changed package.json and it works now.

It would be nice if the packageJSON.pkg config merges with command line config.

robertsLando commented 5 months ago

Would you like to submit a PR? Glad you fixed your issue anyway :)

winjeysong commented 5 months ago

Would you like to submit a PR? Glad you fixed your issue anyway :)

Sure, I will open a PR later 😄