wilix-team / iohook

Node.js global keyboard and mouse listener.
https://wilix-team.github.io/iohook
MIT License
1.2k stars 291 forks source link

iohook build different node js version #420

Open Deliver88 opened 1 year ago

Deliver88 commented 1 year ago

I built the iohook repo and used it in a electron app ending with this issue:

NODE_MODULE_VERSION 93. This version of Node.js requires NODE_MODULE_VERSION 107. Please try re-compiling or re-installing

I am using Electron version: 20.3.7 and Node js version: 16.15.0. I built the iohook with node js version 16.15.0. As I understood, there is no electron version with node_module_version 93, or a node js module version 107. Is there a workaround?

Thanks.

nightincode commented 1 year ago

I just spent 2 days trying to do the same. Here is the fix for your issue:

https://www.electronjs.org/docs/latest/tutorial/using-native-node-modules follow the 3rd code block instructions (the one with export commands). Apply all of these (the first export is the ELECTRON version).

npm run build will do the job or you can use electron-rebuild. Both work. You might run into an issue relating to the NAN libary, this is a known bug and the patch is out there. Once you patch it, it builds correctly (google the error). I have a working build for Mac & Linux for electron 22.1.0 (ABI 110) in combination with Node 16.18.1

The error you are seeing is because the npm is not setup correctly and its linking against the node, it needs the electron.

Deliver88 commented 1 year ago

Hello @nightincode , thank you very much! I will try it.

harismuha123 commented 1 year ago

@nightincode do you mind sharing the prebuilt .tar.gz file if you have it by any chance? I'm using your approach but it isn't really working for a project with Electron 22.

nightincode commented 1 year ago

What os/version?

On Tue, Jun 13, 2023, 11:16 a.m. Haris Muhibic @.***> wrote:

@nightincode https://github.com/nightincode do you mind sharing the prebuilt .tar.gz file if you have it by any chance? I'm using your approach but it isn't really working for a project with Electron 22.

— Reply to this email directly, view it on GitHub https://github.com/wilix-team/iohook/issues/420#issuecomment-1589522450, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARYH2ZIU5CRJR5YF5KM4T5DXLB73HANCNFSM6AAAAAATJC6OXE . You are receiving this because you were mentioned.Message ID: @.***>

harismuha123 commented 1 year ago

@nightincode MacOS 13.4 (22F66) with ARM64 M1, version 22.0.0, ABI 110 (darwin-arm64)

harismuha123 commented 1 year ago

@nightincode iohook 0.9.3

nightincode commented 1 year ago

here you go buddy :) for linux/windows/mac all tested

https://github.com/nightincode/iohook-bins/blob/main/prebuild_libs.zip

(Also includes patched source)

harismuha123 commented 1 year ago

@nightincode hvala :) you have saved my life with this 😄

nightincode commented 1 year ago

Next time you have an issue like this, try my ChatGPT powered plugin to help you solve your issue: shuto.io (now available on the chatGPT plugin store)! You are welcome 👍

harismuha123 commented 1 year ago

@nightincode do you have an ARM64 prebuilt version perhaps? getting the following with this: Error: dlopen(/Users/chern0/Code/droplr-desktop-v2/src/main/custom-packages/iohook/darwin/build/Release/iohook.node, 0x0001): tried: '/Users/chern0/Code/droplr-desktop-v2/src/main/custom-packages/iohook/darwin/build/Release/iohook.node' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/chern0/Code/droplr-desktop-v2/src/main/custom-packages/iohook/darwin/build/Release/iohook.node' (no such file), '/Users/chern0/Code/droplr-desktop-v2/src/main/custom-packages/iohook/darwin/build/Release/iohook.node' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

nightincode commented 1 year ago

You have arm based cpu, you need to rebuild it with the source that is there

nightincode commented 1 year ago

The source code for mac (the patched mac version) is now also available as a zip in the same repo https://github.com/nightincode/iohook-bins

ferothefox commented 1 year ago

Hi @nightincode, can you be a bit more specific than "google the issue"? I've downloaded your repo and I'm able to build a node v18 version, but can't figure out getting Electron 25 for windows and mac to build. I'm on Windows 11 and followed the docs, but still can't figure it out.

npm ERR! code EOVERRIDE
npm ERR! Override for nan@^2.15.0 conflicts with direct dependency

Adding a package.json override to patch the AccessorSignature bug creates that error, and I can't build electron still. Any help would be greatly appreciated.

harismuha123 commented 1 year ago

@FeroTheFox I used the code @nightincode provided to patch iohook and create a new repo that works well with Electron 22 and Node 18: https://github.com/Droplr/iohook-v2. Hope you are able to do the same for 25 on your machine.

ferothefox commented 1 year ago

@harismuha123 Hey Haris, yes, I was able to get it to work on Electron 25! I have a repo here, complete with cross platform builds powered by GitHub Actions. I might retroactively build all of the other major versions, but for now this works for my purposes. The repo is here https://github.com/robolab-io/iohook

For anyone seeing this in the future, if you need a version of iohook built for Electron 25 and Node 18, please check out this release: https://github.com/robolab-io/iohook/releases/tag/v0.9.8