Can't install i2c or ina219 via palette or manually under nodered 4.0.5

My docker compose node red has been very stable and I have multiple backups which also now fail. Because of calls to i2c in settings.js node red will not start. What happened? Is it an auto upgrade to 4.0.5
Anyway I've tried to rebuild eg using palette to install contrib-i2c. I get a long error message that starts with:
npm error code 1
npm error path /data/node_modules/i2c-bus
I get the same when I manually:
cd DockerIOT/nodered
dbash
cd /data
npm install i2c-bus

I have a near identical setup on another PI running 4.0.0 and it loads fine.
I'm sorry that I am a bit out of my depth here but would really appreciate some help.

Is that the full output from running npm install?

Hi not sure what you're asking. The error message is quite long eg when trying to install i2c-bus I get a message which begins with a path error:

2024-10-17T19:30:53.952Z Install : node-red-contrib-i2c 0.9.0

2024-10-17T19:30:53.405Z npm install --no-audit --no-update-notifier --no-fund --save --save-prefix=~ --omit=dev --engine-strict node-red-contrib-i2c@0.9.0
2024-10-17T19:30:57.760Z [err] npm error code 1
2024-10-17T19:30:57.760Z [err] npm error path /data/node_modules/i2c-bus
2024-10-17T19:30:57.760Z [err] npm error command failed
2024-10-17T19:30:57.760Z [err] npm error command sh -c node-gyp rebuild
2024-10-17T19:30:57.760Z [err] npm error gyp info it worked if it ends with ok
2024-10-17T19:30:57.760Z [err] npm error gyp info using node-gyp@8.4.1
2024-10-17T19:30:57.760Z [err] npm error gyp info using node@20.18.0 | linux | arm64
2024-10-17T19:30:57.760Z [err] npm error gyp info find Python using Python version 3.12.7 found at "/usr/bin/python3"
2024-10-17T19:30:57.760Z [err] npm error gyp http GET https://nodejs.org/download/release/v20.18.0/node-v20.18.0-headers.tar.gz
2024-10-17T19:30:57.760Z [err] npm error gyp http 200 https://nodejs.org/download/release/v20.18.0/node-v20.18.0-headers.tar.gz
2024-10-17T19:30:57.760Z [err] npm error gyp http GET https://nodejs.org/download/release/v20.18.0/SHASUMS256.txt
2024-10-17T19:30:57.760Z [err] npm error gyp http 200 https://nodejs.org/download/release/v20.18.0/SHASUMS256.txt
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn /usr/bin/python3
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args [
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '/data/node_modules/node-gyp/gyp/gyp_main.py',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   'binding.gyp',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '-f',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   'make',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '-I',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '/data/node_modules/i2c-bus/build/config.gypi',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '-I',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '/data/node_modules/node-gyp/addon.gypi',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '-I',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '/usr/src/node-red/.cache/node-gyp/20.18.0/include/node/common.gypi',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '-Dlibrary=shared_library',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '-Dvisibility=default',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '-Dnode_root_dir=/usr/src/node-red/.cache/node-gyp/20.18.0',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '-Dnode_gyp_dir=/data/node_modules/node-gyp',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '-Dnode_lib_file=/usr/src/node-red/.cache/node-gyp/20.18.0/<(target_arch)/node.lib',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '-Dmodule_root_dir=/data/node_modules/i2c-bus',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '-Dnode_engine=v8',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '--depth=.',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '--no-parallel',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '--generator-output',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   'build',
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args   '-Goutput_dir=.'
2024-10-17T19:30:57.760Z [err] npm error gyp info spawn args ]
2024-10-17T19:30:57.760Z [err] npm error Traceback (most recent call last):
2024-10-17T19:30:57.760Z [err] npm error   File "/data/node_modules/node-gyp/gyp/gyp_main.py", line 42, in <module>
2024-10-17T19:30:57.760Z [err] npm error     import gyp  # noqa: E402
2024-10-17T19:30:57.760Z [err] npm error     ^^^^^^^^^^
2024-10-17T19:30:57.760Z [err] npm error   File "/data/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 9, in <module>
2024-10-17T19:30:57.760Z [err] npm error     import gyp.input
2024-10-17T19:30:57.760Z [err] npm error   File "/data/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 19, in <module>
2024-10-17T19:30:57.760Z [err] npm error     from distutils.version import StrictVersion
2024-10-17T19:30:57.760Z [err] npm error ModuleNotFoundError: No module named 'distutils'
2024-10-17T19:30:57.760Z [err] npm error gyp ERR! configure error 
2024-10-17T19:30:57.760Z [err] npm error gyp ERR! stack Error: `gyp` failed with exit code: 1
2024-10-17T19:30:57.760Z [err] npm error gyp ERR! stack     at ChildProcess.onCpExit (/data/node_modules/node-gyp/lib/configure.js:259:16)
2024-10-17T19:30:57.760Z [err] npm error gyp ERR! stack     at ChildProcess.emit (node:events:519:28)
2024-10-17T19:30:57.760Z [err] npm error gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:294:12)
2024-10-17T19:30:57.760Z [err] npm error gyp ERR! System Linux 6.6.31+rpt-rpi-2712
2024-10-17T19:30:57.760Z [err] npm error gyp ERR! command "/usr/local/bin/node" "/data/node_modules/.bin/node-gyp" "rebuild"
2024-10-17T19:30:57.760Z [err] npm error gyp ERR! cwd /data/node_modules/i2c-bus
2024-10-17T19:30:57.760Z [err] npm error gyp ERR! node -v v20.18.0
2024-10-17T19:30:57.760Z [err] npm error gyp ERR! node-gyp -v v8.4.1
2024-10-17T19:30:57.760Z [err] npm error gyp ERR! not ok
2024-10-17T19:30:57.762Z [err] npm error A complete log of this run can be found in: /data/.npm/_logs/2024-10-17T19_30_53_535Z-debug-0.log
2024-10-17T19:30:57.767Z rc=1

I think this is the key error

See distutils is removed in Python 3.12 · Issue #2869 · nodejs/node-gyp · GitHub for the reason. Python 3.12 does not have that module. node-gyp was fixed at version 10, but you only have 8.4.1.

Can you drop Python back to 3.10?

I don't know whether it is possible to upgrade node-gyp or if that will cause other problems.

Thanks I'll investigate that. I'm still confused as to what changed my stable setup and why when I restored a known good "tar" backup it still had the problem. I would love to lockdown my system so that this cannot happen.

I don't know about Docker. Does it build the container from the latest node-red docker image each time you instantiate it? Or something like that? If the latest node-red docker image includes that version of python, but not a later version of node-gyp then possibly that should be changed.
@knolleary am I talking rubbish here?

I think you may be right but being new to Docker I don't know how to stop the upgrade (if that's what is happening)

Do you have to use Docket? If not, then don't.

You have a point but all the other elements like Grafana on my Pi are in Docker. I like the idea of everything being in "boxes" and the ease of backup. I'm investigating how to force a download of an earlier version of Nodered to see if that helps.

Docker can be good if you are using a pre-canned application like Grafana, which does not need to access the host hardware and requires minimum configuration to work. For something like node-red I strongly recommend just using the recommended install script. It will make your life easier. You would not have had this problem for example.

Yes you're probably right, but I have invested a lot of time learning Docker and getting Nodered to work in that environment. I had considered that this is the way forward.

Hi Muggins

I use my a compose.yaml file and in it i stipulate which Node-RED to use

Here is an example to load a certain version.

Hope this helps :slightly_smiling_face:


services:

# ------------------------------------------------------------------------------------------
# NodeRED
# ------------------------------------------------------------------------------------------                                                                                                          ---

  node-red:

    image: nodered/node-red:3.1.3                                                           # Make sure I am not using 'latest' as it may get changed in the future and break flows or nodes etc.

    # container_name: - not used

Hi,
I had tried that with various iterations eg 4.0.0 and eventually gave up. However I tried your 3.1.3 and lo and behold it works!! I'm not sure what happens when it pulls down a Nodered docker image. Does it pull down all the node_modules including the ones that seemed to be causing me issues. I had a known good working backup tar file which I have used before to get me out of trouble, but it seems this time when I restored it, it pulled a newer version from the repository. Next question is: Is this a really old version of Nodered and will that cause problems. Also I had no interaction with nodered prior to it crashing so how did it decide to update itself.
Anyway thanks a lot.

Hi,

I am very limited in my knowledge of Docker and Node-RED, but I know enough to get it to work :slightly_smiling_face:

I do know if you don't add anything after image: nodered/node-red it will Always download the latest version

I am guessing your TAR file did not have a defined version of Node-RED, so it updated to the latest.

:+1:

Yes you're right but why did it upgrade itself without intervention.
For interest do you stick with version 3.1.3. I see it's about 9 months old.

Hi,

How do you restart Docker and Node-RED what command do use ?

I have been using v3.1.3 for nearly 9 months and because I do not upgrade it, it works even if my PC crashes due to a power failure and I restart Docker.

I may update one day but thats the good thing about docker, I can choose which Node-RED version I use.

I am sure there are other ways, but it has proven reliable for me.

I use an alias to resart nodered:

alias drestart="docker compose down; docker compose up -d"

I think you need to read this Docker Compose Up Command Explained | Built In

It all depends on what you have setup in your docker-compose.yml file.
Perhaps you could paste the contents of your file here ?

Also this is the command I use to restart Docker, even if my PC has crashed due to power outage.
Everything works fine, this way it doesn't restart the docker-compose.yml
sudo systemctl restart docker

As was suggested: don't run node-red in docker, unless you know what you are doing.

If you want to make it work, you can create your own custom docker file, include all required components manually, build the image and start the container.

I use the alias drestart whilst in the nodered folder. In my case:
cd DockerIOT/nodered
drestart

I used the build outlined by this guy Antonio