Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

robot.js wont work with Electron #466

Open
ExperiBass opened this issue Mar 17, 2019 · 29 comments
Open

robot.js wont work with Electron #466

ExperiBass opened this issue Mar 17, 2019 · 29 comments
Milestone

Comments

@ExperiBass
Copy link

ExperiBass commented Mar 17, 2019

Expected Behavior

App runs and starts logging mouse position

Current Behavior

App doesnt run and spits out this error:

Uncaught Error: The module '/Users/gingkathfox/Documents/GitHub/Bugwars/node_modules/robotjs/build/Release/robotjs.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 64. This version of Node.js requires
NODE_MODULE_VERSION 69. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:160:31)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:722)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:160:31)
    at Module.load (internal/modules/cjs/loader.js:602)
    at tryModuleLoad (internal/modules/cjs/loader.js:541)
    at Function.Module._load (internal/modules/cjs/loader.js:533)
    at Module.require (internal/modules/cjs/loader.js:640)
    at require (internal/modules/cjs/helpers.js:20)
    at Object.<anonymous> (/Users/gingkathfox/Documents/GitHub/Bugwars/node_modules/robotjs/index.js:1)
    at Object.<anonymous> (/Users/gingkathfox/Documents/GitHub/Bugwars/node_modules/robotjs/index.js:38)

Possible Solution

Steps to Reproduce (for bugs)

I cant include much code (private), but here goes:

  1. Install robotjs, Electron, and CraftyJS
  2. Run this code through Electron:
 const robot = require('robotjs')
 const Crafty = require('craftyjs')
 Crafty.init(500,500)
 Crafty.background('black')
 Crafty.e('2D, Canvas, Color')
          .attr({
            x: 20,
            y: 200,
            w: 10,
            h: 10
          })
          .color('green')
          .bind('UpdateFrame', function() {
            console.log(robot.getMousePos())
          })
  1. Watch the error get spit out.

Context

I need to grab the current mouse position to fire a bullet towards it.

Your Environment

  • RobotJS version: 0.5.1
  • Node.js version: 10.15.3
  • npm version: 6.4.1
  • Operating System: darwin (macOS)
@pmlarocque
Copy link

Did you follow the electron installation instruction ? https://github.com/octalmage/robotjs/wiki/Electron
If not this should work:

  1. Require all dependencies you need in the main.js file that is run by electron. (this seemed to be the first important part for me)
  2. Run npm i -D electron-rebuild to add the electron-rebuild package
  3. Remove the node-modules folder, as well as the packages-lock.json file.
  4. Run npm i to install all modules.
  5. Run ./node_modules/.bin/electron-rebuild to rebuild everything
    (from https://stackoverflow.com/questions/46384591/node-was-compiled-against-a-different-node-js-version-using-node-module-versio)

@jackmandelkorn
Copy link

Still can't get this to work.
an extremely long string of errors are occurring when running the last step using electron-rebuild. It seems to rebuild everything just fine until it encounters the robotjs module, and it errors out.
Any help would be appreciated.

@499689317
Copy link

I also encountered this problem.How do you solve this problem?

@masudhossain
Copy link

Bump?

@ExperiBass
Copy link
Author

I also encountered this problem.How do you solve this problem?
#466 (comment)

@meeseekms
Copy link

meeseekms commented Aug 11, 2019

Same here, I can't get it to compile. Please help.

https://pastebin.com/8pFLuz8g

@yomiAdenaike01
Copy link

yeh i have the same problem with electron rebuild

@meeseekms
Copy link

meeseekms commented Aug 15, 2019 via email

@yomiAdenaike01
Copy link

Can that get the color of a pixel from the screen because that's all I need

@meeseekms
Copy link

meeseekms commented Aug 15, 2019

It looks like it does not, just keyboard and mouse controls. One option that comes up in google is using xdotool with grabc which gets the pixel color under the mouse when the screen is clicked. Or you could probably take a screenshot with something and then use something else to get the pixel color at a location in the image. By drawing it to a canvas and then getting the color of a pixel for example, or finding a command line tool that can do it.

edit: assuming you're using linux. I'm not sure what windows tools you'd need to use. Feels weird recommending the use of something else in a project's github, but my first instinct was "ok damn let's try just using an old version of electron that will work with it" since I don't understand compiling errors. And I couldn't really get that to work either so then I realized duh just use a system alternative. So maybe it's helpful advice for other noobs like me.

@PCMACHero
Copy link

Did you follow the electron installation instruction ? https://github.com/octalmage/robotjs/wiki/Electron
If not this should work:

  1. Require all dependencies you need in the main.js file that is run by electron. (this seemed to be the first important part for me)
  2. Run npm i -D electron-rebuild to add the electron-rebuild package
  3. Remove the node-modules folder, as well as the packages-lock.json file.
  4. Run npm i to install all modules.
  5. Run ./node_modules/.bin/electron-rebuild to rebuild everything
    (from https://stackoverflow.com/questions/46384591/node-was-compiled-against-a-different-node-js-version-using-node-module-versio)

Which node modules folder? The one in the electron-rebuild module, or the one in the project folder?

@MakanWG
Copy link

MakanWG commented Oct 20, 2019

The version we get from npm (0.5.1) just won't work as is. It has been released using apis that are now deprecated/deleted, or at least that is what I see in my console output when running rebuild. This should have been fixed with this commit but no new version has been pushed to npm since then.

@oktapodia oktapodia added this to the v0.6.0 milestone Nov 24, 2019
@oktapodia
Copy link
Collaborator

a new version of robotjs supporting the latest NodeJS version will be published soon.

@mike-clark-8192
Copy link

mike-clark-8192 commented Feb 24, 2020

Try rebuilding robotjs with electron-rebuild:

Step 1:
Follow instructions at https://github.com/octalmage/robotjs#building
The last step you need from those instructions is npm install -g node-gyp.

Step 2:

npm install -D electron-rebuild
npx electron-rebuild -f -t prod,optional,dev -w robotjs

If you can get these commands to run without error in your project root (next to your root package.json), it should build you a version of robotjs that works with your Electron. Note that this won't get you all binaries for all platforms, only the platform on which you run the command.

If you're using a version of node+npm that doesn't have npx, or have some other problem, try reading the instructions for alternate ways of running electron-rebuild here: https://github.com/electron/electron-rebuild

Note 1: Alternate invocation: npx electron-rebuild -f -m node_modules/robotjs

Note 2: This has not been tested with ABI > 72, meaning versions of Electron that contain Node v13+. AFAIK there is no stable release of Electron using Node v13+ though.

@ShivamJoker
Copy link

a new version of robotjs supporting the latest NodeJS version will be published soon.

We are waiting please release soon it's causing a lot of problem in electron
Thanks for this great library

@oktapodia
Copy link
Collaborator

This new version has been published (0.6.0) but there is an error in the latest NodeJS version

@ookikoi
Copy link

ookikoi commented Mar 17, 2020

@mike-clark-8192 - worked perfectly for me, thanks! :)

npm i robotjs
npm i -D electron-rebuild
npm install -g node-gyp
npx electron-rebuild -f -t prod,optional,dev -w robotjs

@masudhossain
Copy link

@mike-clark-8192 - worked perfectly for me, thanks! :)

npm i robotjs
npm i -D electron-rebuild
npm install -g node-gyp
npx electron-rebuild -f -t prod,optional,dev -w robotjs

Thanks, this worked. the npx electron-rebuild -f -t prod,optional,dev -w robotjs is key.

@ya3ya6
Copy link

ya3ya6 commented Oct 5, 2020

This worked for me:

  1. remove package-lock.json and nodemodules folder
  2. run npm i
  3. run "./node_modules/.bin/electron-rebuild" -w robotjs

versions:
"electron": "^10.1.3",
"robotjs": "^0.6.0"
"electron-rebuild": "^2.2.0"
node v10.18.0

@mudin
Copy link

mudin commented Dec 24, 2020

@ya3ya6 worked for me too! thanks!

@Jaagrav
Copy link

Jaagrav commented Jan 21, 2021

$ "./node_modules/.bin/electron-rebuild" -w robotjs
⠴ Building module: robotjs, Completed: 0Attempting to build a module with a space in the path
See https://github.com/nodejs/node-gyp/issues/65#issuecomment-368820565 for reasons why this may not work
⠙ Building module: robotjs, Completed: 0gyp info find Python using Python version 3.8.5 found at "C:\Users\Jaagrav\AppData\Local\Programs\Python\Python38-32\python.exe"
⠧ Building module: robotjs, Completed: 0gyp ERR! find VS 
gyp ERR! find VS msvs_version not set from command line or npm config 
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details      
gyp ERR! find VS looking for Visual Studio 2015
gyp ERR! find VS - not found
gyp ERR! find VS not looking for VS2013 as it is only supported up to 
Node.js 8
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:   
gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows        
gyp ERR! find VS **************************************************************
gyp ERR! find VS
✖ Rebuild Failed

An unhandled error occurred inside electron-rebuild
node-gyp failed to rebuild 'D:\Jaagrav's Stuff\Coding\Electron Projex\fidelity\node_modules\robotjs'.
Error: Could not find any Visual Studio installation to use



Error: node-gyp failed to rebuild 'D:\Jaagrav's Stuff\Coding\Electron 
Projex\fidelity\node_modules\robotjs'.
Error: Could not find any Visual Studio installation to use


    at ModuleRebuilder.rebuildNodeGypModule (D:\Jaagrav's Stuff\Coding\Electron Projex\fidelity\node_modules\electron-rebuild\lib\src\module-rebuilder.js:193:19)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Rebuilder.rebuildModuleAt (D:\Jaagrav's Stuff\Coding\Electron Projex\fidelity\node_modules\electron-rebuild\lib\src\rebuild.js:190:9)
    at async Rebuilder.rebuild (D:\Jaagrav's Stuff\Coding\Electron Projex\fidelity\node_modules\electron-rebuild\lib\src\rebuild.js:152:17) 
    at async D:\Jaagrav's Stuff\Coding\Electron Projex\fidelity\node_modules\electron-rebuild\lib\src\cli.js:146:9

Now what? Didn't work for me, I installed Visual Studio with everything required yet it did not work for some reason. Any alternate way?

@ya3ya6
Copy link

ya3ya6 commented Jan 22, 2021

Now what? Didn't work for me, I installed Visual Studio with everything required yet it did not work for some reason. Any alternate way?

@Jaagrav
well it just says install visual studio 2015 or newer (with "Desktop development with C++" selected. it's so important.).
if it didn't work, also try to set "VCINSTALLDIR" and "msvs_version" manually. (google for how to do it).

@Jaagrav
Copy link

Jaagrav commented Jan 22, 2021

I already installed and figured out the problem. To those who are reading this, ignore the shit I wrote above, here's what worked for me on the first try.

In the docs, it clearly mentions this command to rebuild and compile robotjs and electronjs to the same version,

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

What I believe most people are doing wrong, perhaps the reason why this wasn't working for you as well is the --target flag in the command, see how it says 1.1.3 there? Well it's actually supposed to be the electron version that you're using, should've mentioned it in the docs...

So I ran

$ npx electron -v
v11.2.0 //My electron version

and the version was way ahead, I wonder why it wasn't working before. And immediately, literally immediately after I changed and executed this command,

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

Just like literal magic, it worked, in the first try! I spent so long trying to figure this out and the culprit was sitting right in front of my eyes!
However the funny thing is, the commands mentioned above by the other devs, which worked for them didn't seem to work for me and threw me the error that I put in my comment above.

THAT'S IT!

@wikked1
Copy link

wikked1 commented Feb 11, 2021

@Jaagrav you're right you can usually get it working that way if you can figure out your nodejs version, electron version, and ABI version. But why go through the trouble when the electron-rebuild tool is available specifically to make this exact problem easier? Also electron-rebuild can help compile other types of native projects where the exact arguments to rebuild are less clear. It's just a better approach, IMO.

npm i robotjs
npm i -D electron-rebuild
npm install -g node-gyp
npx electron-rebuild -f -t prod,optional,dev -w robotjs

#466 (comment)

@allandiego
Copy link

allandiego commented May 6, 2021

@wikked1 im having similar issue, electron-rebuild build successful node_modules\robotjs\build\Release\robotjs.node

but when i try to use it in the electron i get an error:

ERROR in ./node_modules/robotjs/build/Release/robotjs.node
Module build failed (from ./node_modules/node-loader/dist/cjs.js):
TypeError: this.getOptions is not a function
    at Object.loader (D:\workspace\electron-app\node_modules\node-loader\dist\index.js:20:24)

any idea what could be?

"electron": "12.0.6",
"electron-rebuild": "^2.3.5",

@akky-v
Copy link

akky-v commented Nov 1, 2021

@mike-clark-8192 - worked perfectly for me, thanks! :)

npm i robotjs
npm i -D electron-rebuild
npm install -g node-gyp
npx electron-rebuild -f -t prod,optional,dev -w robotjs

I am facing this kind of error. What should I do?
node-gyp failed to rebuild 'D:\project_path\node_modules\robotjs'.
Error: gyp failed with exit code: 1

@river666
Copy link

I also encountered this problem at now(Mar 19, 2023)
Uncaught Exception:
Error: The module '/private/var/folders/fb/2xlfnbhj5lj29qhf31wz2n900000gn/T/electron-fiddle-83580-6prH9ZrLLrAz/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 82. 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.js:140:31)
image
system:mac
node -v: v12.16.3
"dependencies": {
"robotjs": "0.6.0",
"electron-rebuild": "^2.2.0"
},
"devDependencies": {
"electron": "10.1.3"
}

image
I can't found 82 NODE_MODULE_VERSION.
This problem takes off my so much time.
Anybody can help me?
I tried the method you mentioned, but it didn't work!
Such as follw steps:
npm i robotjs
npm i -D electron-rebuild
npm install -g node-gyp
npx electron-rebuild -f -t prod,optional,dev -w robotjs

@river666
Copy link

I also encountered this problem at now(Mar 19, 2023) Uncaught Exception: Error: The module '/private/var/folders/fb/2xlfnbhj5lj29qhf31wz2n900000gn/T/electron-fiddle-83580-6prH9ZrLLrAz/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 82. 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.js:140:31) image system:mac node -v: v12.16.3 "dependencies": { "robotjs": "0.6.0", "electron-rebuild": "^2.2.0" }, "devDependencies": { "electron": "10.1.3" }

image I can't found 82 NODE_MODULE_VERSION. This problem takes off my so much time. Anybody can help me? I tried the method you mentioned, but it didn't work! Such as follw steps: npm i robotjs npm i -D electron-rebuild npm install -g node-gyp npx electron-rebuild -f -t prod,optional,dev -w robotjs

I solved this problem use a new robotjs.Thx!

@estoylive
Copy link

I CAN'T BELIEVE I HAVE BEEN 2 DAYS STUCK WITH THIS AND CAN'T YET MAKE IT WOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOORK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests