My old flow shows errors after update

Hello,

I had a flow created and it was updated last year. After that i didn't update it. Recently one of my friend updated with this command - "npm install -g --unsafe-perm node-red" and immediately after that my flow was not responding on the browser which was open till then and accessible. I rebooted my raspberry pi4.

After that when I opened the browser to see the flow after the pi rebooted, I noticed many of my previous code showed errors. I have given the screenshots of the errors. Please note that before updating and rebooting the pi same flow was working perfectly fine.

My Node red version is 14.20.0
My npm version is 6.14.17
I'm posting some of the screenshots of errors I'm getting in my flow.



Kindly help me resolve the above error. Also, is there a way to rollback the latest update which could bring back my older version which was compatible with the flow's code?

I think it is the "Code Editor" being very strict about the syntax.
In your first screenshot you need to declare the variables in each of the FOR loops
e.g. for (let i=19; i<37; i++)

You must declare i

typing for in a function node give me this
grafik

for (let index = 0; index < array.length; index++) {
    const element = array[index];
    
}

Calculating a timediff --> use miliseconds


buf needs to be declared somewhere

i use https://flows.nodered.org/node/node-red-contrib-buffer-parser when i must convert buffer data to something else.

Thanks for reply dynamicdave and kitori.

Nice answer but it is really abnormal that an upgrade is able to make code working well going wrong just because more strict syntax control.
An update should not be allowed without informing clearly the list of Java code that will be refused if the update is done.
This is not fair that after an update you need to recheck all code to see if they are still working.

Pierre

The error is a "soft error". Your functions still work. You can also disable the errors directly in the function node by clicking the bulb icon that appears when you put the cursor on any of the errors & chose "disable checks" (I forget the exact option name)

You don't. And you can disable the type checks completely so they never bother you again but you would be doing yourself a disservice.

If you truly wish to remove the things telling you you have potentially "bad code", let me know and I'll tell you how.

Fortunately, I had a back up of the entire pi I had taken then, when the pi was working fine and when the script was created. The very immediate thing I did was, I replaced the SD card of the pi with the old one (back up) and my flow again started working like the original one.

Another work around was (still workable with the updated version) - which is a neater one, is that, I changed the Java script to Type script and replaced the code which was showing errors and it again started working fine.

But I preferred the former approach as it has been working fine for years, so I stick with the older version.

That is, imho, the wrong approach for many reasons not least potential CVEs and recent editor improvements.

As I said before, you can disable the type checking telling you your code is poorly written and it won't bug you to improve it any more. Oh, and I'm case it wasn't clear before, you didn't actually even need to change the code. It runs in the runtime perfectly fine even with the linting errors you are being shown in the editor.