"flow" variable predefined?

I have an obscure question: I just upgraded to the newest node-red, and one of my javascript nodes has a compile error where it says in my own code that "var flow" is already defined.

Has something changed such that "flow" is a reserved function/method?

It says:

Duplicate identifier 'flow'.(2300)
var flow: any

thanks

In Node-RED, the flow context variable is used to access variables that are scoped to the current flow. You do not use flow.path, instead, you use flow.get('variableName') to retrieve a value and flow.set('variableName', value) to store it.

As you have probably updated from a version of node-red that used Ace as the editor to Monaco, Node-red now has better error reporting.

Quick fix remove var.
Best fix use get() and set() , and do not use flow, global and context as variable names.

flow is an internal variable and should not be re-used. I think the reason you are now getting an error is that the function node's code checking is improved with the use of the Monaco editor.

You _could do something like this:

{ // Creates a new localised context
   // const/let restricts this to the localised context
   const flow = {} // or whatever
   ...
}

But better to avoid pre-defined variable/constant names. Also best to use const or let rather than var which can cause hard-to-find bugs.

When using Monaco editor, you can right-click on the variable name and rename it, it will be changed throughout your code for you.

Well I'm glad that's resolved. I've been using "flow" as a variable for a number of years, so will fix that.

Hopefully the design team debated not using common names (like global or flow) instead of special names like _global or global$ or something.

Thanks.

:smiley:

To be fair, I think you may be the only person to have ever hit the issue! :wink:

Also to be fair, the switch from the ACE editor to Monaco really helps with things like this as it spots a lot more seemingly innocuous errors.

As function nodes run in their own node.js VM wrapper, some things such as Node.js's globals are not available. So using global for global context variables isn't so much of an issue.

I like to be a trend setter:-) My JSON has a bunch of flows so the singleton is flow.

Thanks,