Read the statement by Michael Teeuw here.
Need "correct" version of node-libgpiod ....
-
Dear Gurus!
May one of you got an idea…
I’m on my way (looooonnnnggggg planned) to re-implement bugsounet’s MMM-Pir, and I am nearly done…
My last hurdle seems to be the way he has handled the PIR sensor itself. I am not aware if the second way (python script) ever had worked but I stuck with the implementation of the GPIO handler with node-libgpiod.
This works fine in my environment as-is without any problems.
Needed dependeny is node-libgpiod.
I’ve installed this withnpm install node-libgpiod
In my own - brand new - module folder - Ran without any error.
But when mirror is restarted I found an error in logfile, stating that there is a version mismatch…0|MagicMir | [2025-08-06 21:13:55.302] [ERROR] 2025-08-06T21:13:55 <error> [MMM-Pir] [LIB] [PIR] [GPIOD] Error: The module '/home/pi/MagicMirror/modules/MMM-PresenceScreenControl/node_modules/node-libgpiod/build/Release/node-libgpiod.node' 0|MagicMir | was compiled against a different Node.js version using 0|MagicMir | NODE_MODULE_VERSION 115. This version of Node.js requires 0|MagicMir | NODE_MODULE_VERSION 128. Please try re-compiling or re-installing 0|MagicMir | the module (for instance, using `npm rebuild` or `npm install`). (/home/pi/MagicMirror/modules/MMM-PresenceScreenControl/pirLib.js:163 PIR.gpiodDetect)
My Node Version is:
pi@MagicMirrorPi5:~ $ node -v v20.18.1
Information of Mirror:
pm2 info MagicMirror Describing process with id 0 - name MagicMirror ┌───────────────────┬──────────────────────────────────────────┐ │ status │ online │ │ name │ MagicMirror │ │ namespace │ default │ │ version │ 2.31.0-develop │ │ restarts │ 40 │ │ uptime │ 59s │ │ script path │ /home/pi/MagicMirror/installers/mm.sh │ │ script args │ N/A │ │ error log path │ /home/pi/.pm2/logs/MagicMirror-error.log │ │ out log path │ /home/pi/.pm2/logs/MagicMirror-out.log │ │ pid path │ /home/pi/.pm2/pids/MagicMirror-0.pid │ │ interpreter │ bash │ │ interpreter args │ N/A │ │ script id │ 0 │ │ exec cwd │ /home/pi │ │ exec mode │ fork_mode │ │ node.js version │ N/A │ │ node env │ N/A │ │ watch & reload │ ✔ │ │ unstable restarts │ 0 │ │ created at │ 2025-08-06T19:42:31.312Z │ └───────────────────┴──────────────────────────────────────────┘ Divergent env variables from local env ┌────────────────┬─────────────────────────────────────┐ │ SSH_CONNECTION │ 172.23.56.21 53109 172.23.56.157 22 │ │ TERM │ xterm │ │ SHLVL │ 2 │ │ XDG_SESSION_ID │ 4 │ │ SSH_CLIENT │ 172.23.56.21 53109 22 │ │ OLDPWD │ /home/pi/MagicMirror/splashscreen │ └────────────────┴─────────────────────────────────────┘
An “idea” is that there is a mismatch between node version in my terminal and node version used by mirror.
Mirror gave me no information about it’s version…Maybe I’m completely on a wrong way…
Can somebody please guide me?Thanks a LOT!
Warmest regards,
Ralf -
so, if, in the module folder you do
npm rebuild
it will fix the version to the standalone node engine
if you do
electron-rebuild
it should fix the version to the electron embedded node engine
if the engine is the same, only one of those is required
-
@rkorell yes, that is what @electron/rebuild does
recompiles the module (from source) to match
in the magicmirror folder , if not already installed
(my install and upgrade scripts install it for you )npm install @electron/rebuild
then in the module folder do
../../node_modules/.bin/electron-rebuild
a module needing this should have a postinstall script in package.json to invoke this command
-
@sdetweil Dear Sam,
thanks for this information.
Can you please enlighten me?
I can read what you wrote and I got a light idea - but didn’t understand …I definitely have used your install script.
what is @electron and
what correlation is between node-libgpiod and @electron ? and what will this../../node_modules/.bin/electron-rebuild
do?
Sorry for these questions - I would like to understand, what happens.
If this is “neccessary” I will try to automate this for others with a postinstall script.
Thanks for your effort!
warmest regards,
Ralf -
@rkorell javascript is compiled to a byteform by the nodejs engine
there is one embedded inside electron and one outside,
nodejsthe bytecode has a version number.
the engine needs the proper version to execute it
like version 21 added a new instruction, but vers 20 engine cant execute iti dont know the version differences
anyhow, the electron-rebuild application will rebuild the parts of the js code used in the node_helper to match the internal/embedded node engine inside electron
because startup is using the electron app
in server mode we use the mode app
you should know if you run
node serveronly, then the bytecode has to match the nodejs standalone engine version
this is why we try to keep the nodejs/electron internal node versions the same
(there is a node rebuild too) -
@rkorell here is the postinstall i provide for a couple modules
#!/bin/bash base=~/MagicMirror logfile=/dev/null if [ ! -e $base/node_modules/@electron/rebuild ]; then cd $base if [ -e $base/node_modules/.bin/electron-rebuild ]; then # remove the old version npm uninstall electron-rebuild >>$logfile 2>&1 fi # install the new version npm install @electron/rebuild >>$logfile 2>&1 cd - >/dev/null fi $base/node_modules/.bin/electron-rebuild
they changed the name of the npm package
but as i install it as part of install/upgrade
its correct most of the timeand in package.json, in the scripts section add
"postinstall":"./postinstall"
-
@sdetweil said
you should know if you run
node serveronly, then the bytecode has to match the nodejs standalone engine versionOK, thanks.
It seems that rebuild have corrected the error for the module.
When I try to run a node-command in the shell (terminal) then I get an similar error message as above.
Is this caused by your explanation part above?
Different versions needed for either terminal or inside mirror?
Can you tell me HOW the magic mirror is started (when I have used your install script)?Is there a way to test something which had to run in the mirror (like the module) on commandline?
To illustrate what I mean:
I have a very short test-script test-gpiod.js// test-gpiod.js , Aug 2025, Dr. Ralf Korell const { Chip } = require("node-libgpiod"); try { const chip = new Chip(0); console.log("Chip label:", chip.getChipLabel()); } catch (err) { console.error("Error loading chip:", err); }
which I try to run with
node test-gpiod.js
But this produces error message:
/home/pi/MagicMirror/modules/MMM-PresenceScreenControl/node_modules/bindings/bindings.js:121 throw e; ^ Error: The module '/home/pi/MagicMirror/modules/MMM-PresenceScreenControl/node_modules/node-libgpiod/build/Release/node-libgpiod.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 128. This version of Node.js requires NODE_MODULE_VERSION 115. Please try re-compiling or re-installing the module (for instance, using `npm rebuild` or `npm install`). at Module._extensions..node (node:internal/modules/cjs/loader:1586:18) at Module.load (node:internal/modules/cjs/loader:1288:32) at Module._load (node:internal/modules/cjs/loader:1104:12) at Module.require (node:internal/modules/cjs/loader:1311:19) at require (node:internal/modules/helpers:179:18) at bindings (/home/pi/MagicMirror/modules/MMM-PresenceScreenControl/node_modules/bindings/bindings.js:112:48) at Object.<anonymous> (/home/pi/MagicMirror/modules/MMM-PresenceScreenControl/node_modules/node-libgpiod/lib/misc.js:1:37) at Module._compile (node:internal/modules/cjs/loader:1469:14) at Module._extensions..js (node:internal/modules/cjs/loader:1548:10) at Module.load (node:internal/modules/cjs/loader:1288:32) { code: 'ERR_DLOPEN_FAILED' } Node.js v20.18.1
Thanks for any help!
Warmest regards,
Ralf -
@rkorell MM is started by doing node --run or npm start or npm run start
that matches a script in the scripts section of package.json
the MagicMirror installed files support 3 different runtimes
npm start - full using electron
"start:x11": "DISPLAY=\"${DISPLAY:=:0}\" ./node_modules/.bin/electron js/electron.js",
npm run server - server mode only , using node engine
"server": "node ./serveronly",
npm run client - UI mode using electron
node clientonly --address 192.168.1.5 --port 8080
which does this to launch electron, not it doesn’t use the module node_helpers, as its the UI portion
only… the server side (under full, or server only) does thatconst child = require("node:child_process").spawn(electron, elecParams, options);
as I said before, the electron embedded node engines CAN be different than the install standalone nodejs version
node -v
will tell you the standalone node js version.the problem you have, I mentioned in the prior post, if the node versions don’t match, then
you MAY have to recompile when switching runtime choices…npm rebuild
will fix the standalone node version
electron-rebuild
will fix the electron version
I believe the current electron version is 22, and the node version we require is 22
this is because the standalone node version of 24 has dropped support for 32 bit runtimes… and knocks out using the
32 bit legacy raspi OS images that some use…we put out a message to tell the versions when you start MM
VERSIONS: electron: 36.6.0; used node: 22.15.0; installed node: 22.15.0; npm: 10.9.2; pm2: 6.0.8
SO… fun times… keeping the node versions synched will avoid the problem you are encountering
-
@sdetweil
Dear Sam, OK, thanks for this.
Not fully understood…How can I
- figure out, how my mirror is started? (looooong ago I‘ve used your install script and (if I remember correctly) I‘ve answered „yes“ to „do you want automatically start your mirror at system startup“ - or something similar. - Never took care about, what is done - it worked (and still works)…)
- double check the above „VERSIONS“ - message - is this message in logfile?
- can I get „keeping the node versions synched“?
Thanks for further advise!
Warmest regards,
Ralf -
@rkorell 1. my pm2 setup uses the file
~/MagicMirror/installers/mm.sh
you can see that by using the
pm2 info xxxx
command, where xxx is the name or number of the app row in
pm2 status
output, from my desktop , note you CAN setup the SAME NAMED app multiple times,
so the pm2 start app_name
might be ambiguous
so pm2 start 8 would target the app on line 8┌────┬─────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐ │ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │ ├────┼─────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤ │ 8 │ MagicMirror │ default │ 2.32.0… │ fork │ N/A │ 0 │ 245… │ stopped │ 0% │ 0b │ sam │ disabled │ │ 7 │ MagicMirror 8 │ default │ 2.31.0… │ fork │ N/A │ 0 │ 8 │ stopped │ 0% │ 0b │ sam │ disabled │ │ 6 │ MagicMirror1 │ default │ 2.31.0… │ fork │ N/A │ 0 │ 13 │ stopped │ 0% │ 0b │ sam │ disabled │ │ 0 │ Smart Mirror │ default │ 0.0.30 │ fork │ N/A │ 0 │ 31 │ stopped │ 0% │ 0b │ sam │ disabled │ │ 2 │ checkarec │ default │ N/A │ fork │ 2870 │ 19D │ 0 │ online │ 0% │ 3.4mb │ sam │ disabled │ │ 5 │ smart-mirror │ default │ 0.0.31 │ fork │ N/A │ 0 │ 8 │ stopped │ 0% │ 0b │ sam │ disabled │ │ 4 │ smart-mirror ttt │ default │ 0.0.30 │ fork │ N/A │ 0 │ 10 │ stopped │ 0% │ 0b │ sam │ disabled │ │ 3 │ start_alexa_bk │ default │ N/A │ fork │ 2871 │ 19D │ 0 │ online │ 0% │ 2.4mb │ sam │ disabled │ │ 1 │ startspot │ default │ N/A │ fork │ 6315 │ 19D │ 439 │ online │ 0% │ 2.5mb │ sam │ disabled │ │ 9 │ testups │ default │ N/A │ fork │ 2885 │ 19D │ 0 │ online │ 0% │ 3.2mb │ sam
using pm2, you can view the log with
pm2 logs yyy --lines=xxxx
yyy is the name or number of the app from status above), if not supplied,
output from all managed apps is displayed, 1 after the othersxxxx is the count of most recent lines to display (default 15)
you can also see the files(.out and .err, by app) in the
~/.pm2/logs
folder
MM puts out a messages at runtime (this from my desktop system)
[2025-08-09 09:47:38.743] [INFO] System information: ### SYSTEM: manufacturer: System manufacturer; model: System Product Name; virtual: false ### OS: platform: linux; distro: Ubuntu; release: 22.04.5 LTS; arch: x64; kernel: 5.15.0-144-generic ### VERSIONS: electron: 36.6.0; used node: 22.15.0; installed node: 22.15.0; npm: 10.9.2; pm2: 6.0.8 ### OTHER: timeZone: America/Chicago; ELECTRON_ENABLE_GPU: undefined
notice the versions line
keep the node versions synced… yes manually (I use the nodejs version of nvm, called n )
if installed this will show the versions installedn list
and
n
will show the list AND the current one, but you have to type q to exit the list
(because n updates the /usr/local/bin folder, you have to use sudo to actually install or change the active version)or
if you use my install/upgrade script they will make sure the correct standalone version is installedmy scripts install and use n if needed to change versions
-
@sdetweil Dear Sam,
thanks again for this long explanation!My versions (if I interpret correctly) doesn’t mismatch :-(
0|MagicMir | ### SYSTEM: manufacturer: ; model: ; virtual: false 0|MagicMir | ### OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: arm64; kernel: 6.12.20+rpt-rpi-2712 0|MagicMir | ### VERSIONS: electron: 32.2.7; used node: 20.18.1; installed node: 20.18.1; npm: 10.8.2; pm2: 5.4.3 0|MagicMir | ### OTHER: timeZone: Europe/Berlin; ELECTRON_ENABLE_GPU: undefined
So I’m not sure at all, what to do.
pi@MagicMirrorPi5:~ $ n list node/20.18.1
Does show up exact this version, as well.
Where are my problems from ???
Thanks a LOT for any idea!Ralf