Updating, nodejs, and other things

Sorry folks, I know this is a well traveled road.

Most of my machines I use a lot are up to date with NR 3.x.

Lately I've dug up some older machines and they have NR 1.8x on them. (RasPies too.)

And the machine is running .... Jessie I believe.
So node.js is OLD too.

What's happening is I am exporting things from the main machines to them and getting errors. Of course.

So I try to update but am told the node.js is no longer supported (or something like that) and it would be nice to update NR to 3.x

Yes, I get that this means a bit of work on my part.
An update of the O/S would be even better.

So my question is - I hope as briefly as possible:
Can I update to a later node.js than what is used by NR 1.x WITHOUT updating the O/S?

I get it that if that can't be done I really only have 2 choices. Leave alone or update the whole thing.
Just thought I would ask to establish the first part.

Thanks.

Yes, you can. I don't think you'll get problems on Jesse. Just make sure all the OS libraries are up-to-date. Then either use Dave's update script or use a suitable library listed on the Node.js website.

When you've updated node.js, don't forget to do an npm rebuild on both global and your userDir folder.

1 Like

Thanks Julian.

Alas I am going through a few months of bad memory stuff.

I get part but not all of what you said. Sorry.

This is my update script:
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

So checking the O/S libraries are up-to-date..... Lost me.

Isn't that done by the sudo apt update?

Then is it npm update? (no sudo)

Thanks in advance.

Not sure what is in Dave's script. But this will cover you:

sudo apt update && sudo apt upgrade
npm update -g

The script should do everything else anyway.

The machine is running Stretch - not Jesse. Which is better if I remember correctly.

But I can not get node.js to update.

What happens if you add --node18 to the bash command? Preceded by a space of course.

Just to clarify:

npm update -g --node18

From the .node-red directory

pi@PortaPi:~/.node-red $ npm update -g --node18
pi@PortaPi:~/.node-red $ node -v
v8.17.0
pi@PortaPi:~/.node-red $ 

(someone take me out the back and shoot me)

I am having a horrible run of bad luck with getting things working on computers just now.

I meant add it to the pi install script, the bash <(curl ... command.

Sorry. My bad.

So that will overcome the node.js version problem?

bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered) --node18

seems to be working.

All done.

Looked ok.

But....

pi@PortaPi:~/.node-red $ node-red
/usr/lib/node_modules/node-red/node_modules/fs-extra/lib/empty/index.js:13
  } catch {
          ^

SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:617:28)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/lib/node_modules/node-red/node_modules/fs-extra/lib/index.js:8:6)
pi@PortaPi:~/.node-red $ 

Won't run.
:frowning:

Oh, this may be a reason:

pi@PortaPi:~/.node-red $ node -v
v8.17.0
pi@PortaPi:~/.node-red $ 

Searching and looking for how to update the nodejs part:

pi@PortaPi:~/.node-red $ sudo npm install node@16

> node@16.20.1 preinstall /home/pi/.node-red/node_modules/node
> node installArchSpecificPackage

npm ERR! code EACCES
npm ERR! syscall scandir
npm ERR! path /root/.npm/_logs
npm ERR! errno -13
npm ERR! 
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR! 
npm ERR! To permanently fix this problem, please run:
npm ERR!   sudo chown -R 1000:1000 "/root/.npm"
glob error { Error: EACCES: permission denied, scandir '/root/.npm/_logs'
  errno: -13,
  code: 'EACCES',
  syscall: 'scandir',
  path: '/root/.npm/_logs' }
npm ERR! code EACCES
npm ERR! syscall open
npm ERR! path /root/.npm/_cacache/index-v5/dd/7f/965535007b5e6377646cd614059b54639208968a34ca0a0168dfef442a3d
npm ERR! errno -13
npm ERR! 
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR! 
npm ERR! To permanently fix this problem, please run:
npm ERR!   sudo chown -R 1000:1000 "/root/.npm"
module.js:550
    throw err;
    ^

Error: Cannot find module 'node-linux-arm/package.json'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.resolve (internal/module.js:18:19)
    at ChildProcess.<anonymous> (/home/pi/.node-red/node_modules/node-bin-setup/index.js:19:27)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:915:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
npm WARN node-red-project@0.0.1 No repository field.
npm WARN node-red-project@0.0.1 No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node@16.20.1 preinstall: `node installArchSpecificPackage`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node@16.20.1 preinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-08-14T07_19_25_885Z-debug.log
pi@PortaPi:~/.node-red $ 

So I am really confused.

Oh - P.S.
The log file - mentioned at the end - doesn't exist.

Did you update the right pi?

What did you see when the installer script ran - it tells you if node installed. Try running the script WITH --node18 again

Can you also run the following commands to see if you have n or nvm installed:
n
nvm

If either of these are installed, it may be the reason for displaying old node version.

Ok, so on that machine:

(pictures saying 1000 words.)

Then it goes on:

(sorry it is taking a bit of time to run the script)

I'll only do the node-red and not node-red-start.

pi@PortaPi:~/.node-red $ node-red
/usr/lib/node_modules/node-red/node_modules/fs-extra/lib/empty/index.js:13
  } catch {
          ^

SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:617:28)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/lib/node_modules/node-red/node_modules/fs-extra/lib/index.js:8:6)
pi@PortaPi:~/.node-red $ 
pi@PortaPi:~/.node-red $ node -v
v8.17.0
pi@PortaPi:~/.node-red $ 

So node isn't updated.

What do these show?
which node
apt policy nodejs

pi@PortaPi:~/.node-red $ which node
/usr/bin/node
pi@PortaPi:~/.node-red $ apt policy nodejs
nodejs:
  Installed: 8.17.0-1nodesource1
  Candidate: 8.17.0-1nodesource1
  Version table:
 *** 8.17.0-1nodesource1 500
        500 https://deb.nodesource.com/node_8.x stretch/main armhf Packages
        100 /var/lib/dpkg/status
     8.11.1~dfsg-2~bpo9+1 500
        500 http://archive.raspberrypi.org/debian stretch/main armhf Packages
     4.8.2~dfsg-1 500
        500 http://raspbian.raspberrypi.org/raspbian stretch/main armhf Packages
pi@PortaPi:~/.node-red $ 

Also make sure that this runs without error
sudo apt update && sudo apt full-upgrade

pi@PortaPi:~/.node-red $ sudo apt update && sudo apt full-upgrade
Hit:1 https://deb.nodesource.com/node_8.x stretch InRelease         
Hit:2 http://archive.raspberrypi.org/debian stretch InRelease                                  
Hit:3 http://raspbian.raspberrypi.org/raspbian stretch InRelease                               
Ign:4 https://q4os.org/qextrepo q4os-rpi-firefox-cn InRelease            
Err:5 https://q4os.org/qextrepo q4os-rpi-firefox-cn Release
  404  Not Found
Reading package lists... Done
E: The repository 'http://q4os.org/qextrepo q4os-rpi-firefox-cn Release' does no longer have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
pi@PortaPi:~/.node-red $ 

You need to fix that.

Yes, but that is above my skill set.

All I see is that it doesn't/can't update the firefox part.

What you should see is that it has errored out and not completed, therefore nodejs cannot be updated via apt.

Look in /etc/apt/sources.list and delete the relevant line(s) if they are there (or comment them out). If not then look for a file in /etc/apt/sources.list.d/ that provides that repository and delete it (or comment out the contents). Then make sure the update && full-upgrade works, then run the script again.