cryptlex / lexactivator-js

LexActivator API wrapper for Node.js (licensing library)
https://cryptlex.com
MIT License
14 stars 5 forks source link

cryptlex not working when packaged using electron-builder on macos #62

Closed p112913 closed 7 months ago

p112913 commented 7 months ago

I am using the latest cryptlex version for nodeJs 3.25.2 in my electron based app and am running the latest electron version and latest electron-builder version. The app runs fine when running using npm run but when the app is run after being packaged using electron-builder on macos I get the following error:

node:electron/js2c/node_init in process.func [as dlopen] at line 2:2214
node:internal/modules/cjs/loader in Module._extensions..node at line 1356:18
node:electron/js2c/node_init in Object.func [as .node] at line 2:2441
node:internal/modules/cjs/loader in Module.load at line 1126:32
node:internal/modules/cjs/loader in Module._load at line 967:12
node:electron/js2c/node_init in c._load at line 2:13672
node:internal/modules/cjs/loader in Module.require at line 1150:19
node:internal/modules/cjs/helpers in require at line 119:18
app:///node_modules/@cryptlex/lexactivator/lib/lexactivator-native.js in Object.<anonymous> at line 15:30
node:internal/modules/cjs/loader in Module._compile at line 1271:14

It is failing somewhere when the .node files are being accessed in the lexactivator-native.js file. I do not know why is that happening. I checked that in my app.asar archive i have the node_modules/@cryptlex/.../.node files there so i am not sure what the issue is. @adnan-kamili @azan-n can you guys provide any help with this? thanks!

p112913 commented 7 months ago

To add some more context, I can run the packaged version of app completely fine if I exclude cryptlex/lexactivator out of the code so that no calls are made to it and the library is not fetched/required.

adnan-kamili commented 7 months ago

Our library works fine with Electron and many of our customers have been using it since many years. Please ask your questions on our forum or support chat on our website.

p112913 commented 7 months ago

@adnan-kamili thanks for your response. I am trying to understand if there are any specific packaging instructions required for cryptlex/lexactivator when packaging it with electron-builder? As of now I am just treating it as any other library.

p112913 commented 7 months ago

also i did come across this old issue https://github.com/cryptlex/lexactivator-js/issues/9 which seems to be similar to my current problem

adnan-kamili commented 7 months ago

Please confirm if libLexActivator.node files are being copied to the final package. The issue you referred to is no more relevant. And are you facing issues only on macos?

p112913 commented 7 months ago

I havent tried another OS yet but as of now the problem is on macos (arm64). The .node files are present in the app.asar which is the electron's archive: /@cryptlex/lexactivator/lib/bindings/macos/arm64/lexactivator.node

adnan-kamili commented 7 months ago

Please share the exact version of node.js , electron and electron builder you are using so we can have a look.

p112913 commented 7 months ago
Node version: 18.18.2
Electron-Builder version: 24.9.1 
Electron version: 28.2.1
p112913 commented 7 months ago

^ just a FYI that node version is set/controlled by electron so for the latest electron version 28.2.1 the node version is 18.18.2. As an electron app builder I cannot control or change the node version. https://www.electronjs.org/docs/latest/tutorial/electron-timelines#nodejs-version-support

p112913 commented 7 months ago

see if you can get a sample electron app with the same version of electron, electron-builder and cryptlex packaged on macOS arm64.

mumin-khan commented 7 months ago

Hi @p112913. Thanks for reaching out. We are looking into the issue and will get back to you as soon as we have an update.

mumin-khan commented 7 months ago

electron.zip @p112913 We tried replicating your issue in linux as well as macos arm64 (M1) but were unable to replicate it. The working sample electron app is attached for reference.

p112913 commented 7 months ago

@mumin-khan thanks for your help. I was able to narrow down the issue further. It seems that the issue is happening only if code is signed which is what I have to do to release it for production. I was able to run the packaged version fine without code signing once code signing is enabled with cryptlex embedded then the app fails to launch. I am doing some more debugging around it to see. In the mean time are you able to test with codesigning enabled?

p112913 commented 7 months ago

@adnan-kamili @mumin-khan This issue was fixed by adding: "asarUnpack": ["**/*.node"]

to the package.json (under mac build options). Seems like this is required to address native dependencies that have .node files. Without this option set the app fails to launch when codesigning is enabled (on macOS arm64). This looks like a known issue as well and encountered by other users, see this stackOverflow thread: https://stackoverflow.com/questions/71699960/signing-electron-build-for-m1-macs-causes-renderer-to-crash/71759691#71759691

Please update your documentation for nodeJs (for macOS arm64) so that other users know about this. Thanks for all your help! Marking this as closed now.