4

I'm building an Electron application that is expected to run on Ubuntu 20.xx Linux and a Raspberry Pi (Running Raspbian and arch=armv7l) and received the following error:

...was compiled against a different Node.js version using NODE_MODULE_VERSION 72.
This version of Node.js requires NODE_MODULE_VERSION 82. 

I am using a variety of native modules that need to be (node-gyp) compiled to a particular architecture and I'm using mocha as my unit test suite.

I generally install node locally to a given project and that allows me to lock the versions of node and npm to whatever the project requires without too much fuss.

The Electron Native Module Documentation indicates that I should run electron-rebuild after getting this version error.

Unfortunately this has 2 problems for me:

  1. I need to rebuild all native binaries every time I go back and forth between tests and the application, which is unacceptable.

  2. If I ever run npm rebuild, the next run of electron-rebuild exits successfully without rebuilding anything (presumably due to an invalid cache hit).

NOTE: To work around #2, I'm able to proceed with this incantation:

rm -rf node_modules
npm install
electron-rebuild

I've learned some things while investigating this error:

  • The mysterious NODE_MODULE_VERSION value (82 vs 73 in this case) can (ostensibly) be found and matched to a node semver version here: https://nodejs.org/en/download/releases/

  • Logging process.version for the current version of Electron (v10.1.5) indicates the following:

Launching Electron with:
{
  node: '12.16.3',
  v8: '8.5.210.26-electron.0',
  uv: '1.34.2',
  zlib: '1.2.11',
  brotli: '1.0.7',
  ares: '1.16.0',
  modules: '82',
  nghttp2: '1.41.0',
  napi: '5',
  llhttp: '2.0.4',
  http_parser: '2.9.3',
  openssl: '1.1.0',
  icu: '67.1',
  unicode: '13.0',
  electron: '10.1.5',
  chrome: '85.0.4183.121'
}
  • The release info for Node version 12.16.3 (which I have installed) indicate NODE_MODULE_VERSION 72, not 82.
  • NODE_MODULE_VERSION 82 does not appear in any node releases (that I see).
  • Electron Native Module Docs also indicate that I can use npm directly if I set a relatively large collection of environment variables in order to build binaries. When I attempt this, the build fails with, Failed at the lzma-native@6.0.1 install script.

In summary, I would like to install whatever is necessary, so that my local native node & npm binaries are compatible across the Electron runtime and my shell environment and work in both without being rebuilt.

Ah, but how?

Update:

FWIW, node-hid has been rewritten for newer versions of node/Electron, so I'm now running Electron v11.0.3 and node-hid v2.0.0-0.

Luke Bayes
  • 3,234
  • 2
  • 25
  • 20
  • Did you this solution , https://stackoverflow.com/questions/56249103/node-module-was-compiled-against-diffferent-node-module-67/56249648#56249648 – Sharvin K Nov 09 '20 at 09:24
  • Thanks for the pointer! I'm using a few different native modules (pi-spi, node-hid and usb-device). I tried the recommended build step in my pi-spi module (which is what's failing now when I try to run mocha tests). Unfortunately, this didn't allow me to run the tests in mocha, (i.e., outside of Electron). – Luke Bayes Nov 24 '20 at 14:10

1 Answers1

1

Thanks to some tips from Mark Lee with Electron, I learned that we can run electron just like we run node (without launching the full GUI experience).

This made me go looking for a mocha wrapper that uses the electron binary instead of node, and I then found this library: electron-mocha.

One npm install --save-dev electron-mocha and electron-rebuild later, I've got tests running next to my runtime environment from a single Makefile!

Unfortunately, the electron-mocha wrapper doesn't seem to support the "watch" feature of Mocha, but I got that working by using the when-changed (link) Python util.

Luke Bayes
  • 3,234
  • 2
  • 25
  • 20