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-red
image.
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-red
tags for ARM64 defaulted to Alpine Linux, which lacked Python 2 (needed fornode-gyp
compilation). - 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 install
Failure (Current Blocking Issue): When attempting to installnode-red-contrib-modbus
usingnpm install node-red-contrib-modbus@5.43.0 --unsafe-perm --build-from-source
(run asnode-red
user in/data
directory), it consistently fails with the following error related to@serialport/bindings-cpp
compilation: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-gyp
globally: I rannpm install -g node-gyp@latest
asroot
inside the container, which succeeded. However, the subsequentnpm install
for Modbus still reports usingnode-gyp@3.8.0
, indicating it's likely a local dependency of the module overriding the global version. - Clearing
npm
cache:npm cache clean --force
was performed. - Fixing cache permissions: Addressed
EACCES
errors in/data/.npm
by runningchown -R 1000:1000 "/data/.npm"
asroot
. - Deleting problematic module directory:
rm -rf node_modules/@openp4nr/modbus-serial/node_modules/@serialport/bindings-cpp
was 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-red
Docker image tags for ARM64 that are Debian-based and use Node.js 16 or 18 (which might have betternode-gyp
compatibility)? - Or is a custom
Dockerfile
the only guaranteed way to achieve this, and if so, what would be the recommendedDockerfile
configuration (including Node.js version, base image, and build tools) to ensureserialport
compiles correctly?
Any insights or proven solutions would be highly appreciated. Thank you!