octalmage / robotjs

Node.js Desktop Automation.
http://robotjs.io
MIT License
12.38k stars 961 forks source link

Can't run robotjs with electon: The module was compiled against a different Node.js version #646

Open Viiprogrammer opened 3 years ago

Viiprogrammer commented 3 years ago

If i runing electon app with RobotJS, throw error:

Error: The module '\\?\C:\Users\Maxim\node_modules\robotjs\build\Release\robotjs.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 85. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at process.func [as dlopen] (electron/js2c/asar_bundle.js:5:1812)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1203:18)
    at Object.func [as .node] (electron/js2c/asar_bundle.js:5:1812)
    at Module.load (internal/modules/cjs/loader.js:992:32)
    at Module._load (internal/modules/cjs/loader.js:885:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12738)
    at Module.require (internal/modules/cjs/loader.js:1032:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (C:\Users\Maxim\node_modules\robotjs\index.js:1:15)
    at Module._compile (internal/modules/cjs/loader.js:1152:30)

I try to run npm rebuild --runtime=electron --target=11.2.3 --disturl=https://atom.io/download/atom-shell --abi=72 and rebuilding successfuly, but dosen't work.

Environment

111 1111

GDur commented 3 years ago

Others and me had the same problem and this helped: https://github.com/octalmage/robotjs/issues/466#issuecomment-590491327

Would be cool though if they fixed the underlying problem, so that we don't have to recompile. (But maybe the problem is on electrons side)

xujingzhou commented 3 years ago

npm rebuild --runtime=electron --target=9.0.2 --disturl=https://atom.io/download/atom-shell --abi=72

cliqer commented 3 years ago

Use electron-builder and add in your package.json scripts section: "postinstall": "electron-builder install-app-deps"

Each time you run yarn it will re-compile to the electron version you have installed.

msynk commented 3 years ago

it is because all native node modules need a rebuild for electron as described here: https://www.electronjs.org/docs/tutorial/using-native-node-modules

fangjiapeng commented 2 years ago

Not only robojs, when I use node-pty, I got this error. The problem was resolved by using electron-rebuild:

scripts: {
  "rebuild-node-pty": "electron-rebuild -f -w node-pty"
}

run this command manually: npm run rebuild-node-pty

same as node-pty:

scripts: {
  "rebuild-robojs": "electron-rebuild -f -w robojs"
}
bbb169 commented 9 months ago

I found another way to solve this I found a fork of robotjs, and I use this library to replace robotjs, https://github.com/hurdlegroup/robotjs