# Error on function after major upgrade to 3.02

**URL:** <https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391>\
**Category:** General\
**Created:** [10 March 2023 14:11 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391 "2023-03-10T14:11:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [10 March 2023 14:11 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/1 "2023-03-10T14:11:05Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/1/c13db7f2dc55ac4dc0f8522ce015ecc58e15a7d5.png)  
This is the code:

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

 ![immagine](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/2/520780a534ff30e51db2fc58a3a722fe8dc95f19.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [10 March 2023 14:19 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/2 "2023-03-10T14:19:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [10 March 2023 14:27 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/3 "2023-03-10T14:27:42Z")

</div>

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?

```auto
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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/f/1fb5c3def403bf7d4bfd90da3668689d41c0f9fa.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [10 March 2023 14:33 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/4 "2023-03-10T14:33:05Z")

</div>

> [@GiovanniG](#):
>
> , no it's not

Yes it is.

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

```auto
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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND)

[bitwise &](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND)

---

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [10 March 2023 14:35 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/5 "2023-03-10T14:35:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [10 March 2023 14:38 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/6 "2023-03-10T14:38:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [10 March 2023 14:41 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/7 "2023-03-10T14:41:43Z")

</div>

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 ((((

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [10 March 2023 14:47 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/8 "2023-03-10T14:47:07Z")

</div>

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.

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

---

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [10 March 2023 16:26 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/9 "2023-03-10T16:26:21Z")

</div>

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

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

```

Completely different, so I replaced with this:

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

```

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

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [10 March 2023 16:28 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/10 "2023-03-10T16:28:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [10 March 2023 16:31 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/11 "2023-03-10T16:31:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [10 March 2023 16:48 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/12 "2023-03-10T16:48:42Z")

</div>

> [@GiovanniG](#):
>
> I've stop and started NR but no differences in editor. What is wrong here?

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.

---

<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:** [10 March 2023 16:58 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/13 "2023-03-10T16:58:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [10 March 2023 17:02 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/14 "2023-03-10T17:02:49Z")

</div>

> [@E1cid](#):
>
> creating more code that need

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 🙂  
Problem solved, thanks!

---

<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:** [10 March 2023 17:19 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/15 "2023-03-10T17:19:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [10 March 2023 17:22 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/16 "2023-03-10T17:22:19Z")

</div>

> [@GiovanniG](#):
>
> really I can't correct all this code,

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.

---

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [10 March 2023 17:36 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/17 "2023-03-10T17:36:56Z")

</div>

Ok mates, I'll consider it, first I'll try to rebuild the settings.js using the new generated one as [jbudd](https://discourse.nodered.org/u/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

---

<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:** [10 March 2023 17:45 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/18 "2023-03-10T17:45:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [10 March 2023 18:21 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/19 "2023-03-10T18:21:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [11 March 2023 00:32 UTC](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391/20 "2023-03-11T00:32:24Z")

</div>

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

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

[Next page](https://discourse.nodered.org/t/error-on-function-after-major-upgrade-to-3-02/76391.md?page=2)
