# Syntax error on startup

**URL:** https://discourse.nodered.org/t/syntax-error-on-startup/83477
**Category:** General
**Created:** [6 December 2023 18:46 UTC](https://discourse.nodered.org/t/syntax-error-on-startup/83477 "2023-12-06T18:46:31Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Indubots](https://avatars.discourse-cdn.com/v4/letter/i/dbc845/32.png) [@Indubots](https://discourse.nodered.org/u/Indubots)
#### Post date: [6 December 2023 18:46 UTC](https://discourse.nodered.org/t/syntax-error-on-startup/83477/1 "2023-12-06T18:46:31Z")

</div>

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:

```auto

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!

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [6 December 2023 19:05 UTC](https://discourse.nodered.org/t/syntax-error-on-startup/83477/2 "2023-12-06T19:05:43Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [6 December 2023 19:10 UTC](https://discourse.nodered.org/t/syntax-error-on-startup/83477/3 "2023-12-06T19:10:27Z")

</div>

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](http://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.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [6 December 2023 19:27 UTC](https://discourse.nodered.org/t/syntax-error-on-startup/83477/4 "2023-12-06T19:27:04Z")

</div>

> [@Indubots](#):
>
> ```auto
> const globalCreds = credentials.get(node.id)?.map || {}
> ^
> SyntaxError: Unexpected token '.'
> 
> ```

This suggests NODE version running Node-RED is old (does not support [optional chaining](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/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](https://nodered.org/docs/getting-started/raspberrypi)? If you did, all you had to do was append ` --node18` or ` --node20` to the end of it to upgrade.

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [6 December 2023 19:33 UTC](https://discourse.nodered.org/t/syntax-error-on-startup/83477/5 "2023-12-06T19:33:40Z")

</div>

> [@Steve-Mcl](#):
>
> This suggests NODE version running Node-RED is old

At least \<14

> [@marcus-j-davies](#):
>
> Optional Chaining was introduced in Node 14 (I think).

Checking.......

Yup - wasn't available until Node 14

 ![Screenshot 2023-12-06 at 19.32.55](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/b/5b35543514a5519ca86a3cd73d8be0fb29a082da.png)

---

<div class="post-metadata">

### Author: ![Indubots](https://avatars.discourse-cdn.com/v4/letter/i/dbc845/32.png) [@Indubots](https://discourse.nodered.org/u/Indubots)
#### Post date: [6 December 2023 20:16 UTC](https://discourse.nodered.org/t/syntax-error-on-startup/83477/6 "2023-12-06T20:16:52Z")

</div>

Thanks for the fast reponse people!

The full console output is:

```auto

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!

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [6 December 2023 20:23 UTC](https://discourse.nodered.org/t/syntax-error-on-startup/83477/7 "2023-12-06T20:23:08Z")

</div>

> [@Indubots](#):
>
> but I had problems with it as it conflicted with the old version already loaded in the new raspy image

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?

---

<div class="post-metadata">

### Author: ![Indubots](https://avatars.discourse-cdn.com/v4/letter/i/dbc845/32.png) [@Indubots](https://discourse.nodered.org/u/Indubots)
#### Post date: [6 December 2023 20:29 UTC](https://discourse.nodered.org/t/syntax-error-on-startup/83477/8 "2023-12-06T20:29:46Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Indubots](https://avatars.discourse-cdn.com/v4/letter/i/dbc845/32.png) [@Indubots](https://discourse.nodered.org/u/Indubots)
#### Post date: [6 December 2023 20:44 UTC](https://discourse.nodered.org/t/syntax-error-on-startup/83477/9 "2023-12-06T20:44:21Z")

</div>

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

Current functional log is:

```auto
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.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [6 December 2023 20:52 UTC](https://discourse.nodered.org/t/syntax-error-on-startup/83477/10 "2023-12-06T20:52:33Z")

</div>

> [@Indubots](#):
>
> A good option might be to just reflash the raspy image, but I suspect that will get a nodejs v12 in it again

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

---

<div class="post-metadata">

### Author: ![Indubots](https://avatars.discourse-cdn.com/v4/letter/i/dbc845/32.png) [@Indubots](https://discourse.nodered.org/u/Indubots)
#### Post date: [6 December 2023 21:42 UTC](https://discourse.nodered.org/t/syntax-error-on-startup/83477/11 "2023-12-06T21:42:47Z")

</div>

Awesome.  
Thanks again!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [4 February 2024 21:43 UTC](https://discourse.nodered.org/t/syntax-error-on-startup/83477/12 "2024-02-04T21:43:28Z")

</div>

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