Hello everyone,
I'm facing significant challenges trying to get node-red-contrib-modbus working in my Node-RED setup on a Raspberry Pi 4. Previously, when I used Home Assistant Supervised (which includes Node-RED as an add-on), everything worked flawlessly. However, with my current independent Docker Compose setup, I'm hitting a wall.
My Setup:
- Hardware: Raspberry Pi 4 (ARM64 architecture)
- Operating System: Debian (confirmed as Debian 11 Bullseye inside the container)
- Node-RED setup: Docker Compose, pulling an official
nodered/node-redimage.
My Goal: To successfully install and use node-red-contrib-modbus, which relies on serialport for communication with a /dev/ttyUSB0 device (properly mapped in docker-compose.yml).
Steps Taken & Problems Encountered:
- Initial Image Problems: Initially, some official
nodered/node-redtags for ARM64 defaulted to Alpine Linux, which lacked Python 2 (needed fornode-gypcompilation). - Achieved Debian Bullseye: After several attempts with different tags/strategies, I successfully got Node-RED running in a Debian 11 (Bullseye) based container.
- Python 2 Confirmed: I've confirmed that Python 2.7.18 is installed and accessible within the container.
npm installFailure (Current Blocking Issue): When attempting to installnode-red-contrib-modbususingnpm install node-red-contrib-modbus@5.43.0 --unsafe-perm --build-from-source(run asnode-reduser in/datadirectory), it consistently fails with the following error related to@serialport/bindings-cppcompilation:npm error code 1 npm error path /data/node_modules/@openp4nr/modbus-serial/node_modules/@serialport/bindings-cpp npm error command failed npm error command sh -c node-gyp-build npm error gyp info using node-gyp@3.8.0 npm error gyp info using node@20.19.0 | linux | arm64 npm error gyp: Undefined variable standalone_static_library in binding.gyp while trying to load binding.gyp npm error gyp ERR! configure error npm error gyp ERR! stack Error:gypfailed with exit code: 1- Troubleshooting Steps Attempted for
node-gyp:
- Updating
node-gypglobally: I rannpm install -g node-gyp@latestasrootinside the container, which succeeded. However, the subsequentnpm installfor Modbus still reports usingnode-gyp@3.8.0, indicating it's likely a local dependency of the module overriding the global version. - Clearing
npmcache:npm cache clean --forcewas performed. - Fixing cache permissions: Addressed
EACCESerrors in/data/.npmby runningchown -R 1000:1000 "/data/.npm"asroot. - Deleting problematic module directory:
rm -rf node_modules/@openp4nr/modbus-serial/node_modules/@serialport/bindings-cppwas performed before retryingnpm install.
My understanding of the problem: It appears there's an incompatibility between Node.js v20.19.0 and node-gyp@3.8.0 (which serialport is trying to use for compilation). The standalone_static_library variable seems to be the core issue during the gyp configuration step.
My Question: Given this situation, how can I reliably get node-red-contrib-modbus to compile and work in this Docker Compose environment on my Raspberry Pi 4?
- Are there specific official
nodered/node-redDocker image tags for ARM64 that are Debian-based and use Node.js 16 or 18 (which might have betternode-gypcompatibility)? - Or is a custom
Dockerfilethe only guaranteed way to achieve this, and if so, what would be the recommendedDockerfileconfiguration (including Node.js version, base image, and build tools) to ensureserialportcompiles correctly?
Any insights or proven solutions would be highly appreciated. Thank you!