Packaging with pkg doesn't work
s-h-a-d-o-w opened this issue · 12 comments
Obviously, once one has written those small tools using libui, they also need to be distributed somehow...
But I got the following error running the exe pkg generated (Trying to require ...
is debug output that I added in nbind.js):
D:\development\playground_node\libui-node-experiment>libui-node-experiment
Trying to require D:\development\playground_node\libui-node-experiment\node_modules\libui-node\nbind.node
pkg/prelude/bootstrap.js:1176
throw error;
^
Error: Invalid access to memory location.
\\?\D:\development\playground_node\libui-node-experiment\node_modules\libui-node\nbind.node
at Object.Module._extensions..node (module.js:679:18)
at Module.load (module.js:563:32)
at tryModuleLoad (module.js:503:12)
at Function.Module._load (module.js:495:3)
at Module.require (module.js:594:17)
at Module.require (pkg/prelude/bootstrap.js:1157:31)
at require (internal/module.js:11:18)
at initNode (D:\snapshot\libui-node-experiment\node_modules\nbind\dist\nbind.js:142:15)
at D:\snapshot\libui-node-experiment\node_modules\nbind\dist\nbind.js:115:13
at findCompiledModule (D:\snapshot\libui-node-experiment\node_modules\nbind\dist\nbind.js:79:13)
The weird thing is that that file actually exists. And I am able to require that exact path in a dummy script that does nothing else.
Someone reported the same issue with their code here: vercel/pkg#471
But I can't tell what actually causes this and where it should be addressed (pkg, nbind or... could it maybe even be a node bug?). Which is why I create this issue here instead of at nbind - maybe you have sufficient knowledge of the matter to trace it to a definite source and through that make packaging with pkg work.
ping @s-h-a-d-o-w
Holy crap, that actually works, thanks!
Of course one can't distribute files like that. But I hope that your info will help someone figure it out.
I get a different error now by the way - renaming to node.exe also resolves that one:
Error: Module did not self-register.
at Object.Module._extensions..node (internal/modules/cjs/loader.js:729:18)
at Module.load (internal/modules/cjs/loader.js:610:32)
at tryModuleLoad (internal/modules/cjs/loader.js:549:12)
at Function.Module._load (internal/modules/cjs/loader.js:541:3)
at Module.require (internal/modules/cjs/loader.js:648:17)
at Module.require (pkg/prelude/bootstrap.js:1157:31)
at require (internal/modules/cjs/helpers.js:20:18)
at initNode (C:\snapshot\libui-node-experiment\node_modules\nbind\dist\nbind.js:141:15)
at C:\snapshot\libui-node-experiment\node_modules\nbind\dist\nbind.js:115:13
at findCompiledModule (C:\snapshot\libui-node-experiment\node_modules\nbind\dist\nbind.js:79:13)
Renaming the executable to node.exe is a bad way to get it to work.
I kinda fixed this issue with rename-import-dll tool, read how rid works here.
I packaged the app using pkg
How to:
- Paste
rid.exe
into the root directory or add it to the system path, your choice. - run
rid path/to/nbind.node app.exe main.exe
Now it does work, but the node (cmd window?) opens up when I run the main.exe file:
@parro-it any official way of packaging the application? Sorry if I missed any docs regarding this, Thank you
Now it does work, but the node (cmd window?) opens up when I run the main.exe file:
This may help: https://github.com/s-h-a-d-o-w/create-nodew-exe
More info: nodejs/node#556
This may help: https://github.com/s-h-a-d-o-w/create-nodew-exe
More info: nodejs/node#556
The exe file created by this tool exits silently without warnings or errors as soon as it's executed
The exe file created by this tool exits silently without warnings or errors as soon as it's executed
Hmm, perhaps launchui could work for you:
https://github.com/mimecorg/launchui
https://github.com/mimecorg/launchui-packager
https://github.com/mimecorg/launchui-packager-gui
The exe file created by this tool exits silently without warnings or errors as soon as it's executed
I haven't tried it with rid
but I just tried the following and at least that works fine:
pkg -t host showUiTimePicker.js
create-nodew-exe showUiTimePicker.exe node.exe
This also works:
rid ..\..\nbind.node node.exe test.exe
pkg -t host showUiTimePicker.js
create-nodew-exe showUiTimePicker.exe test.exe
Thanks for letting us know about rid
!
The unfortunate thing is that it doesn't fully solve the problem. Because what if the user decides to rename the .exe? I know I sometimes rename files whenever I feel that the devs chose idiotic names. (Like Microsoft calling their things e.g. "vssetup.exe" - how is that helpful? No version number, no nothing...)
And because that has always worked in the past, I'm not confident that I would immediately draw the conclusion "I'm sure it's because I renamed it that it doesn't work any more".
Hmm, perhaps launchui could work for you:
https://github.com/mimecorg/launchui
https://github.com/mimecorg/launchui-packager
https://github.com/mimecorg/launchui-packager-gui
launchui-packager seems to keep the main JavaScript app file exposed in the /app
directory after packaging
@s-h-a-d-o-w I cannot get the create-nodew-exe
tool to work no matter what I try, any idea of what's probably going wrong? I'm on Windows 7 x64, if that'd help :')
I assume getting the resulting .exe to run is the problem, right? Because above, you said that it was able to do the conversion sucessfully.
Did you try the precise commands that I listed?
Because I realized that e.g. once you move the .exe out of the directory, it doesn't work any more.
But why that is... unfortunately, I have no time to debug that right now.
What I will say though is that I doubt that it has anything to do with create-nodew-exe
itself. Because it only changes one byte (probably just diverts a jump or something - I didn't come up with the algorithm). And before it does that, it checks whether the .exe is valid. So... it's very simplistic and should be pretty fool proof.
What I have observed though is that the way node outputs info seems to change once the silent conversion is done. In that (IIRC) - it's not being output to the console any more even if you run it from a console. You have to redirect stdout/stderr to files (see: https://github.com/s-h-a-d-o-w/spotify-ad-blocker/blob/master/src/redirect-output.js#L22-L38), otherwise you won't see anything.
I assume getting the resulting .exe to run is the problem, right? Because above, you said that it was able to do the conversion sucessfully.
Yes, it successfully creates an exe file but nothing happens when I run it
Did you try the precise commands that I listed?
This is the command I'm using: create-nodew-exe app.exe appw.exe