Error on function after major upgrade to 3.02

Hi, I was probably running NR 1.35 before his, on the flow I copied a previous function node, canged inside a string under " " only, and I got the error sign, and when I open function I can't see more the debug that told me where the problem is. There is something wrong with my installation? Thank you
immagine
This is the code:

var messaggio;
var chatId=global.get("LatestchatId");
if (chatId===undefined) {chatId=956528929;}
if (msg.payload) {messaggio="VPN Domotica abilitato";} else {messaggio="VPN Domotica disabilitato";} 
var res = "|Raspberry|: "+messaggio;
msg = {payload:{chatId: chatId, type:"message", content:res}};
if ((chatId!=956528929) & (global.get("NotificheRete"))) {
    msg2 = {payload:{chatId:956528929, type:"message", content:res}};}  else {msg2=null;}
    return [msg,msg2];

I can't understand more where the debug is, how can I know there mistakes are? I can see some red stripes on right coloumn but if I click I don't have reactions

This is due to 3x moving to monaco editor, and reporting more errors in the function editor.

You have not declared msg2 with var, let or const. The red section at right side shows where the error is and msg1 is underlined with a red squiggly line.

Thnaks for reply, no it's not, also this code doesn't work. I'ts strange that in other functions there is the same code but no error, just because I have no edited them after 3.02?

var messaggio; var msg2; var msg;
var chatId=global.get("LatestchatId");
if (chatId===undefined) {chatId=956528929;}
if (msg.payload) {messaggio="VPN Domotica abilitato";} else {messaggio="VPN Domotica disabilitato";} 
var res = "|Raspberry|: "+messaggio;
msg = {payload:{chatId: chatId, type:"message", content:res}};
if ((chatId!=956528929) & (global.get("NotificheRete"))) {
    msg2 = {payload:{chatId:956528929, type:"message", content:res}};}  else {msg2=null;}
    return [msg,msg2];

If I select all text, and only if I select text, I got an icon where the error is, but it doesn't tell me which error is. I can only ignore/etc.
Frankly I don't like this editor, it doesn't help me,opposite it halts me and, even if I'm wrong bucause I can't figure out how it works, I have the feeling it will slow down my work in future.
Any chance to go with the provious editor?
Thanks
immagine

Yes it is.

and the other error is the & in the if statement should be &&
corrected

var messaggio;
var chatId = global.get("LatestchatId");
let msg2 = {}
if (chatId===undefined) {
  chatId=956528929;
}
if (msg.payload) {
    messaggio="VPN Domotica abilitato";
} else {
    messaggio="VPN Domotica disabilitato";
} 
var res = "|Raspberry|: "+messaggio;
msg = {payload:{chatId: chatId, type:"message", content:res}};
if ((chatId!=956528929) && (global.get("NotificheRete"))) {
    msg2 = {payload:{chatId:956528929, type:"message", content:res}};
}  else {
    msg2=null;
}
return [msg,msg2];

&& and operator

bitwise &

Sorry what means exactly "yes it is"?
I've changed & with && and I still have the error.
Why & is an error? It works in other functions

with let msg2 = {}; it works, this is horrible news for me, should I correct all the functions of enterely code? They are more than 400!!!
I'm thinking to downgrade NR, possible?

I confirm that also & is resulting an error now. Mates I'm really worried, I can't sustein a version of NR with editor that is not reporting me more the mistakes and that impose me to correct all code I did previously, I'm really worried.
Please tell me I have chances to revert back to previous version without this problems, and without creating problems to nodes installed after the downgrade.
I'm sad ((((

You can go back to the old ACE editor if you don't want to benefit from the richer features of the monaco editor.

In your settings.js file, under editorTheme you should find a codeEditor section, and in that a property called lib. Set that to ace.

Depending how old your Node-RED instance is, it is possible you don't have some of these sections in your settings file - so you'll have to add them.

editorTheme: {
   codeEditor: {
      lib: "ace"
   }
}

Just remember to backup your settings file before you make changes incase you get the syntax wrong.


Just to add... the monaco editor is telling you about improper javascript code. It won't stop your flows from working - its just warning you. You could choose to ignore it, and fix the syntax issues in the function nodes gradually over time.

1 Like

Thank you for your kind help, this is what I have:

    // Customising the editor
    editorTheme: {
        projects: {
            // To enable the Projects feature, set this value to true
            enabled: false
        }
    },

Completely different, so I replaced with this:

    // Customising the editor
editorTheme: {
   codeEditor: {
      lib: "ace"
   }
},

I've stop and started NR but no differences in editor. What is wrong here?

Completely different, so I replaced with this:

In general, best not to completely replace things so you don't remove settings you already had. In this instance, the projects setting you had set to the default value so it doesn't matter that you removed it.

Are you sure you've edited the right settings file? Node-RED logs the full path to the settings file it is using when it starts up.

1 Like

Yes I'm sure is the same path, I've just verified it again.
How should then I write properly into that file? I'm getting a bit confused, why I don't see any result?

Did you refresh your browser?

Why go back to Ace?
It does not report you syntax issues, which means you will be creating more code that need correcting.

1 Like

Switching back to ace is similar to adding all your misspellings to your custom dictionary. I.e. you will continue to make mistakes.

You can keep Monaco fix your bad code OR keep Monaco and switch off that particular warning in your settings file.

1 Like

Sorry, I forgot to refresh the page. I did and the editor is ace, good.
Please one more question, if I understood right I don't need to worry about the fact I removed projects setting, right?

Sorry mates I appreciate your effort you improved the interface and syntyax correction, but really I can't correct all this code, I have too many risk it will not work after and I can't take this risk. I prefer stay old and dont' see errors, all is working by the way and stable, for me is ok. Plus I can see where my mistakes are, sorry but with new interface I've checked everwhere and I haven't see the help. I have no choce and I'll stay old :slight_smile:
Problem solved, thanks!

You might consider stopping Node-red, renaming settings.js and restarting NR.

This will create a new default settings.js file including all the goodies introduced since your v1.3.5
Compare it with the backup copy to see what you were missing.

You can then edit it and change the word "monaco" to "ace" to ensure you can continue using variables without declaring them first.

1 Like

Note that where you had & instead of && is a real error, the meaning is different. Under some circumstances the effect is the same, but a subtle change in the data could make it fail at some point in the future. Such errors can be extremely difficult to find. That is why it is worth using the new editor, and each time it points out a problem then fix it. One such subtle bug could take you much longer to find than it would take to fix the issues now.
Also you will presumably continue to include errors in new code. If you are using node-red in a work environment then your employer will not thank you if you leave behind poor quality code for the next guy to fix.

1 Like

Ok mates, I'll consider it, first I'll try to rebuild the settings.js using the new generated one as jbudd suggested, then I'll evaluate if I can debug function with an error reporting interface. Since now I haven't seen it and I couldn't work without it.
Then if I can find it helpful, as for sure it will be, then I'll evaluate to correct all the code time by time.

Pity that during the upgrade the settings.js hasn't been properly refreshed, since this I opened this topic, now all has sense. Thank you again

One of the features introduced in more recent releases is Node-red lint.

I'm not very familiar with it so I have no idea if it will highlight all the occurrences of uninitiated variables, & where you should have && and || where you should have ??.

Worth a look at least, it might give you an idea of the size of the debugging task ahead.

1 Like

Another way to locate all the & would be to export your entire flow (in 'pretty' format) and save it to a file.

Then edit the file and do a search for &. Then you can find that node's id. Next, in NR, do a 'find' using that id and change the node...

OR, if you need to change all the occurrences, you could do a global replace while editing the file. Then you would stop NR and rename the existing flow file (the default name is flow.json) to something like oldflow.json. Start NR and import the changed file.

1 Like

I've analyzed both settings.js, removing all comments, compacting everything to read better, this is what I miss (including the "Monaco" lines)

flowFile: 'flows.json',
flowFilePretty: true,
 uiPort: process.env.PORT || 1880, is not now under  module.exports = {
diagnostics: {
enabled: true,
ui: true,
},
runtimeState: {
enabled: false,
ui: false,
},

logging: {
console: {
level: "info",
metrics: false,
audit: false}
},
exportGlobalContextKeys: false,
externalModules: {    },
editorTheme: {
palette: {
},
projects: {
enabled: false,
workflow: {
mode: "manual"
}
},

codeEditor: {  
lib: "monaco",
options: {
}
}
},
functionExternalModules: true,
functionGlobalContext: { },

It's a lot missing here, a major update directly to 3.02 from 1.35 is not recomended
I'll give a chance to run those parameters, I have 2 questions:

  1. viceversa, in the new file I don't see this: credentialSecret: false, I've never set them, I don't need to encript anything, should I miss it?
  2. in the old settings flowFile: 'flows.json', is missing, how can load my json without this info?