Hot questions for Using ZeroMQ in electron

Question:

I'm using Windows 7 x64, nodejs 5.1.0 and Electron 0.35. I followed the instructions from Electron Quick Start app and then added the line require("zmq") to the main.js. At this point, after npm install zmq --save, electron main.js displays:

Error: Could not locate the bindings file. Tried: [list of zmq.node paths]

One of the paths tried is actually present in the system, i.e. node_modules/zmq/build/Release/zmq.node

If I remove the Electron app code and leave just the require("zmq") line in main.js, I can successfully run with node main.js. How am I supposed to get rid of the error when running with Electron?


Answer:

Figured it out after reading Using Native Node Modules. Basically, after each npm install of a native package, it needs to be rebuilt with Electron headers by issuing .\node_modules\.bin\electron-rebuild.cmd.

Question:

Introducing zmq into my Electron app has proved to be onerous:

01:33:03 {master %=} rgbkrk@puter ~/code/jupyter-sidecar$ electron .
dyld: lazy symbol binding failed: Symbol not found: __ZN2v89Signature3NewEPNS_7IsolateENS_6HandleINS_16FunctionTemplateEEEiPS5_
  Referenced from: /Users/rgbkrk/code/jupyter-sidecar/node_modules/zmq/build/Release/zmq.node
  Expected in: dynamic lookup

dyld: Symbol not found: __ZN2v89Signature3NewEPNS_7IsolateENS_6HandleINS_16FunctionTemplateEEEiPS5_
  Referenced from: /Users/rgbkrk/code/jupyter-sidecar/node_modules/zmq/build/Release/zmq.node
  Expected in: dynamic lookup

/usr/local/bin/electron: line 2: 46288 Trace/BPT trap: 5       "/usr/local/lib/node_modules/electron-prebuilt/dist/Electron.app/Contents/MacOS/Electron" "$@"

How should I be bundling zmq? All I did to get it setup as part of the environment is running npm install --save zmq.


Answer:

You can use zeromq.js.

It has the same API as zmq but features prebuilt static binaries for Node and Electron. So there is no need for a proper C/C++ compiler toolchain:

npm install zeromq

For Electron specific instructions checkout https://github.com/zeromq/zeromq.js#rebuilding-for-electron.

Question:

I am have a huge headache from trying to get the ZMQ Node bindings working with Electron, especially on Windows. I am working on Windows 7 and Ubuntu 16.04 and both of them have two separate issues.

On Windows, I get an error when I try to do require('zmq')

C:\vueelectron\app\node_modules\bindings\bindings.js:91 Uncaught Error: Could not locate the bindings file. Tried:
 → C:\vueelectron\app\node_modules\zmq\build\zmq.node
 → C:\vueelectron\app\node_modules\zmq\build\Debug\zmq.node
 → C:\vueelectron\app\node_modules\zmq\build\Release\zmq.node
 → C:\vueelectron\app\node_modules\zmq\out\Debug\zmq.node
 → C:\vueelectron\app\node_modules\zmq\Debug\zmq.node
 → C:\vueelectron\app\node_modules\zmq\out\Release\zmq.node
 → C:\vueelectron\app\node_modules\zmq\Release\zmq.node
 → C:\vueelectron\app\node_modules\zmq\build\default\zmq.node
 → C:\vueelectron\app\node_modules\zmq\compiled\6.1.0\win32\x64\zmq.node

I've tried compiling with VS 2013 and 2015, rebuilt multiple times, used electron-rebuild nothing seems to be working.

On Linux it loads up fine but the problem is that when I send a message, it seems to get stuck in a loop somewhere and it keeps sending sending hundreds of messages and goes on doing that indefinitely. This was resolved by upgrading from the version of ZMQ in the Ubuntu repositories to the latest one downloaded from the ZeroMQ website.

This is the code I used in my index.html file of my Electron app.

const electron = require('electron')
const zmq = require('zmq')

const socket = zmq.socket('req')
socket.connect('tcp://10.10.0.51:3111')

socket.on('message', function (data) {
  console.log(socket.identity + ': answer data ' + data)
})

socket.send('test')

Has anyone else been able to get Electron + ZMQ working? If so, what is your development enviroment like? Thanks.


Answer:

The problem is the unmatched node.js binary that is delivered by Electron and your version of node. The long answer is that you need to compile Electron and ZeroMQ with the same Node.js headers. Here is the response from Electron community http://github.com/electron/electron/issues/6805. There's a short answer now though!

Use zeromq in place of zmq (same API). zeromq provides prebuilt binaries for electron and node.js for OS X, Windows, and macOS/OS X. After installing zeromq, rebuild for the version of electron you're using:

npm rebuild zeromq --runtime=electron --target=1.4.5

Thanks to the zeromq.js team and have fun with ZeroMQ!