Electron/Java incompatibility?


#1

We are getting a strange error message when we try to run a basic script using electron that includes the java package. Here is a terminal session that demonstrates the problem:

bash-4.2$ more package.json
{
  "name": "nava_node_test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "electron": "^1.4.1",
    "java": "^0.7.2"
  }
}
bash-4.2$ more index.js 

console.log ("Hello World~~");
var java = require ('java');

bash-4.2$ node index.js 
Hello World~~
bash-4.2$ node_modules/electron/dist/electron index.js
Hello World~~
App threw an error during load
Error: Module version mismatch. Expected 50, got 48.
    at Error (native)
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:168:20)
    at Object.Module._extensions..node (module.js:583:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:168:20)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/u/fisher23/javaNodeTest/node_modules/java/lib/nodeJavaBridge.js:21:16)
A JavaScript error occurred in the main process
Uncaught Exception:
Error: Module version mismatch. Expected 50, got 48.
    at Error (native)
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:168:20)
    at Object.Module._extensions..node (module.js:583:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:168:20)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/u/fisher23/javaNodeTest/node_modules/java/lib/nodeJavaBridge.js:21:16)

If I comment out the java require statement, it works fine. Any ideas why the java package works with node but not electron?

John


#2

That Java bridge relies on a native Node addon/module, so it must be rebuilt to target Electron as documented in http://electron.atom.io/docs/tutorial/using-native-node-modules/


#3

I followed the directions to “Installing modules and rebuilding for Electron”, but when I ran the electron-rebuild script after doing a successful “npm install”, I got the following error:

gyp ERR! clean error 
gyp ERR! stack Error: ENOTEMPTY: directory not empty, rmdir 'build/Release'
gyp ERR! stack     at Error (native)
gyp ERR! System Linux 3.10.0-327.36.1.el7.x86_64
gyp ERR! command "/opt/node-v6.7.0-linux-x64/bin/node" "/u/fisher23/javaNodeTest/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /u/fisher23/javaNodeTest/node_modules/nslog
gyp ERR! node -v v6.7.0
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok 

Look familiar to anyone?


#4

Delete the node_modules directory and rerun npm install.


#5

I tried that but got the same error result each time.


#6
gyp ERR! stack Error: ENOTEMPTY: directory not empty, rmdir 'build/Release'

This tells you that the build/Release directory isn’t empty. Try removing that instead of node_modules.


#7

I tried removing my node_modules and doing a “fresh start” multiple times, but always get the same error.


#8

What’s interesting is that if I run electron-rebuild a second time, it then starts compiling, but then crashes on this error:

../src/javaObject.cpp:350:18: error: ‘class v8::Object’ has no member named ‘SetHiddenValue’
   javaObjectObj->SetHiddenValue(Nan::New<v8::String>(V8_HIDDEN_MARKER_JAVA_OBJECT).ToLocalChecked(), Nan::New<v8::Boolean>(true));
                  ^
make: *** [Release/obj.target/nodejavabridge_bindings/src/javaObject.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/u/fisher23/javaNodeTest/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Linux 3.10.0-327.36.1.el7.x86_64
gyp ERR! command "/opt/node-v6.7.0-linux-x64/bin/node" "/u/fisher23/javaNodeTest/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /u/fisher23/javaNodeTest/node_modules/java
gyp ERR! node -v v6.7.0
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok 

Any idea why? Argh, sure wish we could get this to work.


#9

Ok, looks like the first error, (“ENOTEMPTY”) was happening because when I installed electron-rebuild, I used --save instead of --save-dev. Which I switched to --save-dev, I now get the Java compile error the first time. And, that appears to be a known issue, described here:

So, I’ll follow that thread, and hopefully there will be a resolution to this problem.


#10

This happens because the SetHiddenValue API was removed in V8 5.2 (Electron 1.3.0 and later), I’ve fixed this issue in v8-profiler before, someone just needs to do the same with the Java bridge module.


#11

What’s strange is that when I do the initial Java Bridge installation, it compiles just fine; it’s only when I do the electron-rebuild that I get this error.


#12

That’s to be expected. When you first install it it’s compiled for
whichever version of Node you have installed, Node uses an older version of
V8 than Electron so everything compiles fine.


#13

I tried to use the java module before with this project, if you get it to work even a simple project I would be very interested in seeing it and maybe getting some instructions if you’re so willing to share.

Thank you


#14

I believe the root of the problem is being worked here:

I’ve got a fairly specific set of steps listed to reproduce the problem.