Robotjs: Using robotjs in electron app

Created on 14 May 2016  Â·  21Comments  Â·  Source: octalmage/robotjs

Hello,

I would like to use RobotJS in an Electron app. My program works well with Node but when I run it in Electron I get the following error: A dynamic link library (DLL) initialization routine failed. node_modulesrobotjsbuildReleaserobotjs.node

I believe this is the source of the problem https://github.com/electron/electron/blob/v0.37.2/docs/tutorial/using-native-node-modules.md#using-native-node-modules
However, I am having trouble figuring out how to fix this on my own because I'm new to developing in general. Is there any chance you can make a prebuilt or something that works with electron?

Most helpful comment

I was having a similar issue.

First I deleted entire node_modules directory and reinstalled them again by running npm installin project directory (you have to define all modules&versions in a package.json file for that).

Then removed robotjs from node_modules directory manually. And then ran .\node_modules\.bin\electron-rebuild.cmd.

After that I installed robotjs again by npm install robotjs.

Then cd .\node_modules\robotjs and node-gyp rebuild --runtime=electron --target=1.3.3 --disturl=https://atom.io/download/atom-shell --abi=48 (1.3.3 is current version of electron)

and problem solved!

All 21 comments

Hi there,

Have you tried running electron-rebuild? I use RobotJS with Electron on Mac and that allows my app to run.

I have tried electron-rebuild but I'm not sure if I'm doing it right. I'm on windows and when I run
.node_modules.binelectron-rebuild.cmd
I get the following message:
Error: ENOENT: no such file or directory, stat ' node_moduleselectron-rebuildlibheaders.node-gyp1.0.1common.gypi'
at Error (native)
I found that the path is actually iojs-1.0.1 instead of 1.0.1, so I tried changing the name of the folder to just 1.0.1 and that got rid of the error but it still looks like it doesn't rebuild the module.

Hmm, I would try updating your Node version. io.js is obsolete and it's possible that electron-rebuild doesn't support it.

My node version is up to date. I just found this though. https://github.com/electron/electron-rebuild/issues/66
Looks like it's a problem with electron rebuild, no wonder I wasn't able to get it working. Hopefully it will work again soon.

Well that explains it! I was really confused by the iojs in the URL. Let me know if you need anything else from my end!

Have you tried running electron-rebuild on windows?
They have fixed the iojs error now, but after I rebuild I am still getting the error (DLL) initialization routine failed. node_modulesrobotjsbuildReleaserobotjs.node
If I delete robotjs.node and run rebuild, the robotjs.node file comes back so rebuild is apparently doing something, but the last modified date of the file is always 09.05.2016 01:40. Shouldn't that date change to the current date if the module has been rebuilt?

Not recently, I personally use Mac and electron-rebuild works there. Could you try one of the other methods they list? It seems like on Windows electron-rebuild is downloading one of the prebuilt RobotJS binaries, which won't work for electron. You could also try RobotJS v0.4.1, which was before the prebuilt binaries existed.

I'll try to look into this tonight in a VM.

I'm trying to use robotjs with electron-rebuild, too, actually I'm getting this error:

Error: Module version mismatch. Expected 48, got 47.
    at Error (native)
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:158:20)
    at Object.Module._extensions..node (module.js:568:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:158:20)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)
    at Module.require (module.js:466:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/egon/Entwicklung/Electron/BotApp/node_modules/robotjs/index.js:1:94)

I don't see which module is expected to have version 48...

Hi there, could you try either the npm or the node-gyp way listed on that page? The module mismatch error means the version of Node used to build RobotJS doesn't match the version in Electron.

Sorry here's the link:

https://github.com/electron/electron/blob/v0.37.2/docs/tutorial/using-native-node-modules.md#the-npm-way

Either one of those should work!

It looks like this command will also work:

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

Change target to your Electron version. You can use this in your package.json to rebuild RobotJS automatically:

https://github.com/codeforscience/sciencefair/blob/master/package.json#L9

Thanks, I got it to work. I had to upgrade my node.js to 6.2.1 (it was 5.x before).
Then it worked with the easy way:

./node_modules/.bin/electron-rebuild

I was having a similar issue.

First I deleted entire node_modules directory and reinstalled them again by running npm installin project directory (you have to define all modules&versions in a package.json file for that).

Then removed robotjs from node_modules directory manually. And then ran .\node_modules\.bin\electron-rebuild.cmd.

After that I installed robotjs again by npm install robotjs.

Then cd .\node_modules\robotjs and node-gyp rebuild --runtime=electron --target=1.3.3 --disturl=https://atom.io/download/atom-shell --abi=48 (1.3.3 is current version of electron)

and problem solved!

Thank you so much @olciniz ! This solved my problem too!

Nice. Do the docs need to be updated to reflect this?

This is not a nessesarily an issue with RobotJS, it's Electron that operates outside of the norm. That said, I did create an issue to document this process.

https://github.com/octalmage/robotjs/issues/236

@Zyphdoz :i am getting the same error . i tried rebuild using :-
"rebuild": "npm rebuild --runtime=electron --target=1.1.3 --disturl=https://atom.io/download/atom-shell --abi=48"

@Zyphdoz :i am getting the same error . i tried rebuild using :-
"rebuild": "npm rebuild --runtime=electron --target=1.1.3 --disturl=https://atom.io/download/atom-shell --abi=48" .

hello,
I'm trying to use robotjs with electron-rebuild, too, actually I'm getting this error:

ERROR in ./node_modules/robotjs/build/Release/robotjs.node 1:2
    Module parse failed: Unexpected character '�' (1:2)
    You may need an appropriate loader to handle this file type.
    (Source code omitted for this binary file)
     @ ./node_modules/robotjs/index.js 1:14-53

how to do with this?

↑ me too..

hello,
I'm trying to use robotjs with electron-rebuild, too, actually I'm getting this error:

ERROR in ./node_modules/robotjs/build/Release/robotjs.node 1:2
    Module parse failed: Unexpected character '�' (1:2)
    You may need an appropriate loader to handle this file type.
    (Source code omitted for this binary file)
     @ ./node_modules/robotjs/index.js 1:14-53

how to do with this?

@senro I was able to resolve this particular issue in my project by adding a new rule to handle the .node extension to my webpack.config.js: https://webpack.js.org/loaders/node-loader/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

itsashis4u picture itsashis4u  Â·  10Comments

tms1337 picture tms1337  Â·  4Comments

vnsharma-systango picture vnsharma-systango  Â·  9Comments

IChocolateKapa picture IChocolateKapa  Â·  12Comments

HopefulLlama picture HopefulLlama  Â·  3Comments