Illegal Instruction after npm install on old pi zero, but ok using install script

As mentioned in this post I installed node-red on an original Pi zero using the recommended install script. It installed node red 4.0.9 and nodejs 20 and node-red runs fine.

However, I find that if I npm remove node-red (leaving nodejs20 installed) and then re-install the same version using of node-red using
sudo npm install -g --unsafe-perm node-red
then when I run node-red it just says Illegal Instruction.

If I then remove node-red again run the script again then all is once more working.

In the failing mode I tried running npm rebuild in /usr/lib and in the .node-red directory but that made no difference.

I am guessing that for some reason the wrong architecture of something is being installed, but can't see what the difference is when run via the script. Has anyone any ideas?

Do you have the Linux build tools installed on the Pi? I'm wondering if something is trying to compile a binary library and failing for some reason?

Yes.
There are no errors that I can see, I increased the log level on npm and nothing looks out of place.

OK, next step would be to increase the verbosity of the npm install to see if that throws up any clues.

I am running it with loglevel verbose now. If nothing obvious I will hack the install script to do the same and see if there are any differences.

1 Like

I am getting somewhere now. It isn't the install itself that is different. I inserted an exit statement in the script right after the install and then I get the illegal instruction error again. I will have to look carefully at what comes after. I am not installing the pi specific nodes so it isn't that.

1 Like

I have found it, I should have seen it hours ago. I thought I had looked through this bit of the script, but there I now see

            # If armv6 then remove the bcrypt binary to workaround illegal instruction error
            if uname -m | grep -q armv6l ; then
                $SUDO rm -rf /usr/lib/node_modules/node-red/node_modules/@node-rs | $SUDO tee -a /var/log/nodered-install.log >>/dev/null
            fi

Doh!

1 Like

Yup, as expected, a C library that requires compilation. Presumably not compatible with whatever C compiler is present on that device. I vaguely seem to remember that it has a JavaScript fallback version?

It doesn't try and build it, I think the problem is that it is provided as a pre-compiled binary and is not available for armv6 architecture.

Ah, OK. I think it should try to build it if a pre-built version doesn't exist. Possibly the make config for armv6 has been removed if it is no longer supported.

Well (re) found. I had forgotten about that.. I must have been having a good day to suss that out originally :slight_smile:

1 Like

Do you know why npm installs an invalid version rather than trying to build it from source, or at least throwing an error?

Sorry Colin, can't remember whether you said this. But did you try installing the raw library into a dummy npm package? Does it give the same error? I don't have any Pi Zero's to try it on I'm afraid.

Can’t recall, but as we also install a pure js version as a backup it was easier just to go with that rather than suffer the vagaries of build tools