Monday, 29 April 2019

How can I rebuild zeromq.js bindings for electron version 4.1.4?

In attempting to use zeromq.js in an Electron app, I found that the NODE_MODULE_VERSIONS did not appear to match:

Uncaught Error: Cannot open /home/XXXX/ptt_geo/ptt-geo-fork/src/webapp/node_modules/zeromq/build/Release/zmq.node: Error: The module '/home/XXXX/ptt_geo/ptt-geo-fork/src/webapp/node_modules/zeromq/build/Release/zmq.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 Object.<anonymous> (vendor.js:217837)
    at Object../node_modules/zeromq/build/Release/zmq.node (vendor.js:217838)
    at __webpack_require__ (runtime.js:79)
    at Object../node_modules/zeromq/lib/index.js (vendor.js:217866)
    at __webpack_require__ (runtime.js:79)
    at Object../node_modules/zeromq/index.js (vendor.js:217850)
    at __webpack_require__ (runtime.js:79)
    at Object../src/app/services/aic-contact-listener.service.ts (main.js:4042)
    at __webpack_require__ (runtime.js:79)
    at Object../src/app/components/map/map.component.ts (main.js:1874)

According to the internet, I need to rebuild zeromq.js using the following command:

 npm rebuild zeromq --runtime=electron --target=<ELECTRON_VERSION>

And so I ran it for my version of electron (4.1.4) and got the following error on rebuild:

gyp WARN install got an error, rolling back install
gyp ERR! configure error 
gyp ERR! stack Error: 404 response downloading https://nodejs.org/dist/v4.1.4/node-v4.1.4-headers.tar.gz
gyp ERR! stack     at Request.<anonymous> (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/install.js:214:14)
gyp ERR! stack     at Request.emit (events.js:194:15)
gyp ERR! stack     at Request.onRequestResponse (/usr/lib/node_modules/npm/node_modules/request/request.js:1066:10)
gyp ERR! stack     at ClientRequest.emit (events.js:189:13)
gyp ERR! stack     at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:556:21)
gyp ERR! stack     at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
gyp ERR! stack     at TLSSocket.socketOnData (_http_client.js:442:20)
gyp ERR! stack     at TLSSocket.emit (events.js:189:13)
gyp ERR! stack     at addChunk (_stream_readable.js:284:12)
gyp ERR! stack     at readableAddChunk (_stream_readable.js:265:11)
gyp ERR! System Linux 3.10.0-693.el7.x86_64
gyp ERR! command "/usr/local/lib/nodejs/node-v10.15.3-linux-x64/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/XXXX/ptt_geo/ptt-geo-fork/src/webapp/node_modules/zeromq
gyp ERR! node -v v10.15.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! zeromq@5.1.0 install: `node scripts/prebuild-install.js || (node scripts/preinstall.js && node-gyp rebuild)`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the zeromq@5.1.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

This error comes after gcc builds the library file successfully, and seems to indicate it's trying to grab node.js headers for a version 4.1.4, which doesn't exist.

Under the hood, the electron-rebuild stuff uses node-abi, so I dug a little deeper and did some experimenting, and it appears no matter what when I pass in electron as the runtime, node-abi is trying to use the target as node to determine what headers to grab instead of electron. This can be verified, for example, by passing

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

This rebuilds successfully, and should indicate building with electron 5.0, which has a NODE_MODULE_VERSION of 70, however if I build and look at the Electron error again, I instead get a NODE_MODULE_VERSION of 47 (vs. required 69), which corresponds to a node.js version of 5.0.0!

I've verified this several times in that when I pass in a target that matches an existing node.js version, I get back a matching NODE_MODULE_VERSION in the Electron error. So thinking that the documentation might just be wrong, and that target should really be the node.js version and not the Electron version, I punched in the node.js version associated with my Electron build:

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

Only to have node-abi come back and say "I don't understand that:"

Error: Could not detect abi for version 10.11.0 and runtime electron.  Updating "node-abi" might help solve this issue if it is a new release of electron
    at getAbi (/home/XXXX/ptt_geo/ptt-geo-fork/src/webapp/node_modules/node-abi/index.js:30:9)
    at module.exports (/home/XXXX/ptt_geo/ptt-geo-fork/src/webapp/node_modules/prebuild-install/rc.js:71:57)
    at Object.<anonymous> (/home/XXXX/ptt_geo/ptt-geo-fork/src/webapp/node_modules/prebuild-install/bin.js:9:25)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
    at startup (internal/bootstrap/node.js:283:19)

Which matches what I'm seeing in node-abi's index.js (there's nothing in there that tells it what to do for node version 10.11.0).

Is this a bug of some kind, and if so, is there a recommended workaround?

Versions of software used:

Electron: 4.1.4

Zeromq: 5.1.0

Node: 10.11.0

Node-abi: 2.8.0 (released today, yay...?)



from How can I rebuild zeromq.js bindings for electron version 4.1.4?

No comments:

Post a Comment