Struggling to install node-red-contrib-modbus on Raspberry Pi 4 (Debian + Docker Compose) - gyp: Undefined variable error

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:

  1. Initial Image Problems: Initially, some official nodered/node-red tags for ARM64 defaulted to Alpine Linux, which lacked Python 2 (needed for node-gyp compilation).
  2. Achieved Debian Bullseye: After several attempts with different tags/strategies, I successfully got Node-RED running in a Debian 11 (Bullseye) based container.
  3. Python 2 Confirmed: I've confirmed that Python 2.7.18 is installed and accessible within the container.
  4. npm install Failure (Current Blocking Issue): When attempting to install node-red-contrib-modbus using npm install node-red-contrib-modbus@5.43.0 --unsafe-perm --build-from-source (run as node-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: gyp failed with exit code: 1
  5. Troubleshooting Steps Attempted for node-gyp:
  • Updating node-gyp globally: I ran npm install -g node-gyp@latest as root inside the container, which succeeded. However, the subsequent npm install for Modbus still reports using node-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 running chown -R 1000:1000 "/data/.npm" as root.
  • Deleting problematic module directory: rm -rf node_modules/@openp4nr/modbus-serial/node_modules/@serialport/bindings-cpp was performed before retrying npm 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 better node-gyp compatibility)?
  • Or is a custom Dockerfile the only guaranteed way to achieve this, and if so, what would be the recommended Dockerfile configuration (including Node.js version, base image, and build tools) to ensure serialport compiles correctly?

Any insights or proven solutions would be highly appreciated. Thank you!

What is the reason for using python 2 ?