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

Unable to build #373

Open hazaart opened 2 years ago

hazaart commented 2 years ago

Every build fails with the following error

Error: The module '\?\C:\Users*****\Documents\Workspace\activity-check\node_modules\iohook\builds\node-v72-win32-x64\build\Release\iohook.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 87. This version of Node.js requires NODE_MODULE_VERSION 72. Please try re-compiling or re-installing the module (for instance, using npm rebuild or npm install).

I have tried rebuild, install and also the electron-rebuild script. Nothing works

Update: after installing a new LTS of node I'm getting a new error: Cannot find module 'C:\Users*****\Documents\Workspace\activity-check\node_modules\iohook\builds\node-v93-win32-x64\build\Release\iohook.node'

hazaart commented 2 years ago

Any support? you can basically recreate this issue with a new project from any node version and iohook version to my findings.

marcelblum commented 2 years ago

Can you provide the build command line you were trying? And provide some more context to those error messages? You mentioned Electron but your errors reference the iohook build for Node; what environment/version are you trying to build for?

hazaart commented 2 years ago

I am indeed using the Node build on Node version 16.13.0 and my app is using typescript. Here's a snippet of my package.json:

  "scripts": {
    "tsc": "tsc --build --verbose",
    "start": "tsc && nodemon ./dist/main.js",
    "release": "tsc & pkg ./dist/main.js --output ./dist/activity-check.exe"
  },
  "dependencies": {
    "express": "^4.17.1",
    "iohook": "^0.9.3",
    "typescript": "^4.5.2"
  },
  "devDependencies": {
    "@types/node": "^12.20.37",
    "nodemon": "^2.0.15",
    "pkg": "^5.4.1"
  }
BrOrlandi commented 2 years ago

I'm also having problem on Windows.

I just try to run my application and I get this error:

PS C:\Users\Bruno\GitHub\beybot> node .\server.js
refresh_locale_list [476]: GetKeyboardLayoutList(0, NULL) found 1 layouts.
refresh_locale_list [493]: Received 1 locales.
load_input_helper [866]: refresh_locale_list() found 1 locale(s).
node:internal/modules/cjs/loader:1183
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: The module '\\?\C:\Users\Bruno\GitHub\beybot\node_modules\iohook\builds\node-v93-win32-x64\build\Release\iohook.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 82. This version of Node.js requires
NODE_MODULE_VERSION 93. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1183:18)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\Bruno\GitHub\beybot\node_modules\iohook\index.js:24:21)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12) {
  code: 'ERR_DLOPEN_FAILED'
}

I tried on Node 10, 16,17 and with iohook 0.7.2 and 0.9.3

marcelblum commented 2 years ago

When iohoook installs, it tries to detect your current environment and download prebuilt binaries for your platform. As of now prebuilds are only available for up to Node v15 (abi 88). If you need to use Node v16+ you would have to build iohook manually for it to work. Otherwise the easier option would be to use Node <=15.

If the prebuild didn't already download for you or you've changed Node versions since installing iohook you can download the needed prebuild from https://github.com/wilix-team/iohook/releases/

Helpful maintained list of Node & Electron abi #s: https://github.com/electron/node-abi/blob/main/abi_registry.json

If you're trying to build manually for multiple versions and get that ...was compiled against a different Node.js version message, on Windows I've found that sometimes you have to clear the node-gyp cache to avoid filename/version conflicts \AppData\Local\node-gyp\Cache

dmatora commented 2 years ago

I'm using node v14 and tried to use different electron version from 14 to 20 I've tried to download iohook repo and build iohook using commands like node build.js --runtime electron --version 14.0.0 or node build.js --runtime electron --version 20.0.0 I always get error like

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

I've downloaded node-abi packages and went through all kind of

nodeAbi.getTarget('83', 'node')
nodeAbi.getTarget('83', 'electron')
nodeAbi.getTarget('107', 'node')
nodeAbi.getTarget('107', 'electron')

and found no abi version that could be used both with election and abi

Is there any combination of node version and electron version that can get iohook working? How does it work for anyone?

dmatora commented 2 years ago

Ok, eventually I've launched

node build.js --runtime electron --version 14.0.0 --abi 89

And was able to use it with Electron 14.0.0

node build.js --runtime electron --version 18.0.0 --abi 103 also works and makes Electron 18.0.0 working All later versions fail to download node headers and build