Syntax error on startup

Hello there people!

Im trying to run Node-red in a Raspberry 3B+.
I had some problems updating the components but I finally got this versions installed:

node v21.4.0
npm 10.2.4

Now, when I try to run it, I get this error:


Starting as a systemd service.
/usr/local/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/Flow.js:164
                    const globalCreds = credentials.get(node.id)?.map || {}
                                                                 ^
SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/index.js:19:12)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
nodered.service: Main process exited, code=exited, status=1/FAILURE
nodered.service: Failed with result 'exit-code'.
nodered.service: Consumed 2.875s CPU time.

It seems there's an interpreter missmatch somewhere.
Any advice?
Thanks!

Hi @Indubots - Welcome to the forums

Please can you show the complete start up log of Node RED?
I'm suspicions about the Node version,

Optional Chaining was introduced in Node 14 (I think).
and the error you have provided suggest a lesser version of Node JS as its struggling with optional chaining

My Raspberry Pies with Node-red do not have a /usr/local/lib/node_modules directory, which makes me think that you perhaps didn't use the script from nodered.org documentation to install?

That currently gives me
node.js version: v18.18.2
npm version: 9.8.1
node-red version: v3.1.0

node.js version 18 is currently preferred. 20 is ok but gives problems with some nodes.

1 Like

This suggests NODE version running Node-RED is old (does not support optional chaining)

I realise you stated you are using NODE v21 (odd numbers are NOT recommended) but I suspect you have n or nvm or some other Node Version Manager and the NODE version node-red is loading is NOT v21.

In your settings file, on the first line, enter console.log('process.versions.node', process.versions && process.versions.node)

Start node-red, check your log


Other questions, as this is a Rasperry PI, how did you install Node + Node-RED? I assume you did NOT use the official installer script? If you did, all you had to do was append --node18 or --node20 to the end of it to upgrade.

1 Like

At least <14

Checking.......

Yup - wasn't available until Node 14

Thanks for the fast reponse people!

The full console output is:


Start Node-RED
 
Once Node-RED has started, point a browser at http://192.168.1.116:1880
On Pi Node-RED works better with the Firefox or Chrome browser
 
Use   node-red-stop                          to stop Node-RED
Use   node-red-start                         to start Node-RED again
Use   node-red-log                           to view the recent log output
Use   sudo systemctl enable nodered.service  to autostart Node-RED at every boot
Use   sudo systemctl disable nodered.service to disable autostart on boot
 
To find more nodes and example flows - go to http://flows.nodered.org
 
Starting as a systemd service.
/usr/local/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/Flow.js:164
                    const globalCreds = credentials.get(node.id)?.map || {}
                                                                 ^
SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/index.js:19:12)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
nodered.service: Main process exited, code=exited, status=1/FAILURE
nodered.service: Failed with result 'exit-code'.
nodered.service: Consumed 2.612s CPU time.

Where can I find that log file you mention?
if I use the
node-red-log
command I get the exact same output.
I did use the script from this website you mentioned, but I had problems with it as it conflicted with the old version already loaded in the new raspy image.
How could I uninstall it all and try again clean?
Thanks!

Show us what happened / what errors you got. In short, it should work and we need to know why it did not.

NOTE: You did not answer questions about nvm - this is very likely the cause of the error.

If you run nvm -v or which nvm, what do you see?

I dont have a detailed log on the past errors. The main problem was that it detected a version 12 and refused to install a new one.
nvm -v returns
0.39.6
which nvm returns nothing.

A good option might be to just reflash the raspy image, but I suspect that will get a nodejs v12 in it again.

Success!!!
Forcing a reinstall with the --node20 option enabled solved the issue.

Current functional log is:

Start Node-RED
 
Once Node-RED has started, point a browser at http://192.168.1.116:1880
On Pi Node-RED works better with the Firefox or Chrome browser
 
Use   node-red-stop                          to stop Node-RED
Use   node-red-start                         to start Node-RED again
Use   node-red-log                           to view the recent log output
Use   sudo systemctl enable nodered.service  to autostart Node-RED at every boot
Use   sudo systemctl disable nodered.service to disable autostart on boot
 
To find more nodes and example flows - go to http://flows.nodered.org
 
Starting as a systemd service.
process.versions.node 20.10.0
6 Dec 17:40:29 - [info]
Welcome to Node-RED
===================
6 Dec 17:40:29 - [info] Node-RED version: v3.1.1
6 Dec 17:40:29 - [info] Node.js  version: v20.10.0
6 Dec 17:40:29 - [info] Linux 6.1.21-v7+ arm LE
6 Dec 17:40:32 - [info] Loading palette nodes
6 Dec 17:40:32 - [debug] Module: node-red-contrib-buffer-parser 3.2.2 /home/indubots/.node-red/node_modules/node-red-contrib-buffer-parser
6 Dec 17:40:32 - [debug] Module: node-red-contrib-play-audio 2.5.0 /home/indubots/.node-red/node_modules/node-red-contrib-play-audio
6 Dec 17:40:32 - [debug] Module: node-red-node-pi-gpio 2.0.6 /home/indubots/.node-red/node_modules/node-red-node-pi-gpio
6 Dec 17:40:32 - [debug] Module: node-red-node-ping 0.3.3 /home/indubots/.node-red/node_modules/node-red-node-ping
6 Dec 17:40:32 - [debug] Module: node-red-node-random 0.4.1 /home/indubots/.node-red/node_modules/node-red-node-random
6 Dec 17:40:32 - [debug] Module: node-red-node-serialport 2.0.2 /home/indubots/.node-red/node_modules/node-red-node-serialport
6 Dec 17:40:32 - [debug] Module: node-red-node-smooth 0.1.2 /home/indubots/.node-red/node_modules/node-red-node-smooth
6 Dec 17:40:35 - [info] Settings file  : /home/indubots/.node-red/settings.js
6 Dec 17:40:35 - [info] Context store  : 'default' [module=memory]
6 Dec 17:40:35 - [info] User directory : /home/indubots/.node-red
6 Dec 17:40:35 - [warn] Projects disabled : editorTheme.projects.enabled=false
6 Dec 17:40:35 - [info] Flows file     : /home/indubots/.node-red/flows.json
6 Dec 17:40:35 - [info] Creating new flow file
6 Dec 17:40:35 - [debug] loaded flow revision: d751713988987e9331980363e24189ce
6 Dec 17:40:35 - [debug] red/runtime/nodes/credentials.load : no user key present
6 Dec 17:40:35 - [debug] red/runtime/nodes/credentials.load : using default key
6 Dec 17:40:35 - [debug] red/runtime/nodes/credentials.load : keyType=system
6 Dec 17:40:35 - [warn]
---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.
If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.
You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------
6 Dec 17:40:35 - [warn] Encrypted credentials not found
6 Dec 17:40:35 - [info] Server now running at http://127.0.0.1:1880/
6 Dec 17:40:35 - [info] Starting flows
6 Dec 17:40:35 - [debug] red/nodes/flows.start : starting flow : global
6 Dec 17:40:35 - [info] Started flows

Thanks everyone for your time an patience!

I'll post progress info form time to time.

1 Like

Yes, then you run the script with --nodeNN problem solved.

Awesome.
Thanks again!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.