vercel / pkg

Package your Node.js project into an executable
https://npmjs.com/pkg
MIT License
24.33k stars 1.02k forks source link

Cannot use external c-bindings within pkg exe, causes immediate failure when trying to load package. #1966

Closed EzzypooOfNazareth closed 1 year ago

EzzypooOfNazareth commented 1 year ago

What version of pkg are you using?

5.8.1

What version of Node.js are you using?

16.13.1

What operating system are you using?

Windows 10

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

I have a package installed that I would like to use within my pkg application, it's the node-raylib bindings found here, which are a c-bindings for the raylib game framework. Apologies in advance if this is not an appropriate issue considering it involves a specific npm package.

node-raylib

I am able to run my pkg application without this dependency which leads me to believe that pkg cannot run, or has issues including, c bindings into js. The executable builds fine for all operating systems. However, even when playing around with most of the --options flags, and including the .node, .bak, and node-raylib files into the exe directory I am unable to get the app running. I used a console.log to identify where the application was failing and I'm able to see that the application runs as expected until the raylib import. I'm currently unsure if this is a bug or a yet-to-be implemented feature.

The running console log is able to show in the console, however upon the first import of node-raylib, the exe fails and crashes with no further output to the console. image

image

Expected Behavior

Expect the application to be able to open a window via the raylib graphics library and to display game content.

To Reproduce

Create a node project.

run npm i raylib run npm i -D pkg if the cli is not installed globally run pkg source_file copy the node-raylib.bak and node-raylib.node files to the exe directory. (I have no idea if this is necessary, but it was recommended to me via the raylib reddit page) attempt to run executable

Console will show for a brief second then immediately will crash

matthias-heller commented 1 year ago

Have you tried recreating the directory structure and paste the binary where it normally is located. In our case we load an sqlite c-binding.

we have the following structure

/my.exe /node_modules/better-sqlite3/build/Release/better_sqlite3.node The path of the better_sqlite3.node file is the same as inside node_modules folder. This works at least under debian-linux as well as windows
github-actions[bot] commented 1 year ago

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[bot] commented 1 year ago

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