Bug in function editor (Cannot redeclare block-scoped variable)

Hi All,

I'm surprised I didn't find anyone else to report this bug:
When using constants or variables in a function node with the same name both at the "On Start" and "On Message" section the editor throws an error message Cannot redeclare block-scoped variable and does a red underline below the variables.
I tried "const", "let" and "var". The error will show up always.
Still I can save and successfully run the node so it's only cosmetical but it might be worth fixing.

Or is the whole thing intended behavior and I'm to blind to see the reason for it and that's why I can't find anyone else reporting that bug?

I tested this with ace as well as monaco - but I cannot confirm:

[
    {
        "id": "d0fd04357f17d46f",
        "type": "function",
        "z": "b808fb4094db08d8",
        "name": "function 33",
        "func": "const test = 18;\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "// Der Code hier wird ausgefĂĽhrt,\n// wenn der Node gestartet wird\nlet test = 15;",
        "finalize": "// Der Code hier wird ausgefĂĽhrt,\n// wenn der Node gestoppt wird\nlet test = 19;",
        "libs": [],
        "_mcu": {
            "mcu": false
        },
        "x": 490,
        "y": 120,
        "wires": [
            [
                "b3d26ecbc6d74b59"
            ]
        ]
    },
    {
        "id": "10f17f127a6858bd",
        "type": "inject",
        "z": "b808fb4094db08d8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "_mcu": {
            "mcu": false
        },
        "x": 300,
        "y": 120,
        "wires": [
            [
                "d0fd04357f17d46f"
            ]
        ]
    },
    {
        "id": "b3d26ecbc6d74b59",
        "type": "debug",
        "z": "b808fb4094db08d8",
        "name": "debug 115",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "_mcu": {
            "mcu": false
        },
        "x": 670,
        "y": 120,
        "wires": []
    }
]

Could you please provide a short flow that shows the issue?

I don't use monaco
but if someone can reproduce this, might be worth raising on GitHub.

@Mike-FUT
Can you advise of:

  • Browser
  • Node Version
  • Node RED Version

Perhaps because it isn't happening for others? I can't reproduce it I'm afraid. Win11, Vivaldi browser, latest Node-red, node.js v18

I am seeing it
Node-RED v3.0.2
Node.js v20.2.0

Not able to access my 3.1.3 server at the moment

My bad... I forgot to post the details.

Browser: Firefox 121 and Chrome 120
Node Version: 18.18.2 and 18.19.0 (Npm 10.2.3)
Node RED Version: 3.1.0 and 3.1.3

Tabs "On Start" and "On Message".
Sometimes it requires to hit the enter key or other key presses on one tab so the error shows up on the other tab. On the tab where anything is changed the error disappears but still shows up on the other tab.

I believe I have seen this issue already a long while ago.

Example flow:

[
    {
        "id": "3c780662f9dd4911",
        "type": "function",
        "z": "deb9ccecbf2319fe",
        "name": "function 50",
        "func": "let test=1;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 1,
        "initialize": "let test=1;\n",
        "finalize": "",
        "libs": [],
        "x": 530,
        "y": 240,
        "wires": [
            []
        ]
    }
]

Looks exactly the same here. It will show a red mark on the function node, it will warn me when deploying, but it works perfectly.

I am not seeing it (just installed latest in a test rig)

  • 3.1.3 | 20.10.0 | Safari

A little inconclusive this one

  • Mike (3.1.3)
  • E1cid (3.0.2)
  • Julian (3.1.3)
  • Marcus (3.1.3)
  • Jeff (3.1.3)

No problem here

3.1.3 | 18 | Edge

nr bug

Brand new created function.

Is that 3.1.3?

It is.
And I believe it has been like this for ages.

Odd - I still cant reproduce it

Related to the underlaying OS? My understanding about how Node RED works under the hood isn't good enough to judge if that makes sense.
I'm using: Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-169-generic x86_64)

Btw, just started Edge that I never use. Same issue with latest MS Chromium Edge. First time I started that on this machine so it can't be related to any cookies, cache or whatever.

The points off interest will usually be.

  • Browser.
  • Node RED version.

Node version and OS shouldn't (normally) make a difference, as its UA/Client based

Strange one.

Issues are raised here if you wanted to pursue it : Issues · node-red/node-red · GitHub
Ensure to provide your environment detail and what versions you are seeing it against

Thank you, I'll file a bug tomorrow.
I'll wait a bit more, probably someone has noticed that already and found the reason but considering my memory that it's been out there for ages and E1cid sees that issue on 3.0.2 it could be easily since beginning of v3.
So to repeat my initial comment: I'm surprised nothing has been reported so far. Luckily I'm not the only one experiencing it. :slightly_smiling_face:

1 Like

3.1.1 | 16 | Chrome => can't reproduce!
3.1.3 | 18 | Chrome => Yeap! See it... ! :+1:

1 Like

Just for completeness

3.1.3 | 20 | Safari => can't reproduce!

reproducibility seems apparent - I would probably raise it

if I am not mistaken

3.1.3 | 20 | Safari
3.1.3 | 18 | Vivaldi
3.1.1 | 16 | Chrome
3.1.3 | 18 | Edge
3.1.3 | 18 | Chrome
3.1.3 | 20 | Chrome
3.1.0 | 18 | FF
3.1.3 | 18 | Chrome
3.0.2 | 20 | Chrome

I am also seeing in 3.1.3 / 20 / chrome

There's a comment in the source that might give some hints:

//as models are signleton, consts and let are avialable to other javascript instances
//so when not focused, set editor mode to text temporarily to avoid multiple defs
2 Likes