Cannot find name 'flow' (error 2304) and red squiggle under `msg`

When I write 'let data = flow.get("data")' in the function node, an error will be reported

Where are you seeing that error? Can you post a screenshot please?

Also, which version of node-red are you using?

Node-RED version: v4.0.9
Node.js version: v22.14.0
Thank you!

Please select the three nodes with the red triangles and Export them to the clipboard (CTRL+E or Export in the menu) and paste it here. When pasting, in order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

See this post for more details - How to share code or flow json

let data = msg.payload;
data = JSON.parse(data);
msg.payload = data;
return msg;

I don't think it's a problem with the code. The same code runs normally on another computer. Could it be related to the version of nodejs or that some packages of Node-Red did not load properly?

Can you try it in a different browser?
If it is the same in another browser then check the browser developer console for errors.

We have seen this type of error before - where the editor doesn't recognise the built-in variables we define. My search skills are failing to find the previous threads on it.. but @Steve-Mcl may have better recall than I do on it.

I am struggling to think of the search terms necessary to find a previous posting :thinking:

@xpxiong can you check the browsers console (devtools F12)

Also, what browser is this and what version?

Lastly, can you check your node-red logs - is node-red crashing / restarting without you realising?

My browser version is 135.0.7049.115 (official version) (64-bit). I think it's a problem with the back-end program because when I disconnect from the server and then edit the code of the function node, it won't report an error。Besides, I won't view the required information in the console.

I remember now.

There was a similar incident discussed on a node-red slack channel. The user was not getting types delivered.

Unfortunately I forget the reason.

It was either...

  • Due to proxy or firewall blocking
  • Browser plugin
  • Type files missing on their node-red installation

Please do the following (Keep Dev tools open)...

  1. Select the network tab in dev tools.
  2. Refresh the page
  3. Open a function node
  4. Check for non 200 response codes

Edit: here is a screenshot the slack thread

It is indeed very likely that there are some limitations in the company network, but there are no issues regarding server errors in my console. thank you

All your responses are ~275b - that is definitely your issue. I suspect the company or browser policy setting or something is returning something else

This is what they should be

If you click one of the ts files, then preview what do you see?

I see this:

Thank you very much for helping me find the problem. Figure 1 shows the content of the ts file when accessing the server. Figure 2 shows the content of the ts file when the server is accessed. Figure 3 shows accessing the contents of the ts file in the normally running node-red locally. The size of all their ts files is approximately around 275B.
I'm wondering if it was caused by my setting the node-red password locally and then directly copying the project to the server.



That should have no bearing.

The issue looks like a network thing.

What do you see if you select preview for this entry?


One more test

  • Leave the dev tools open
  • disable the cache
    • image
  • refresh the browser

Do you now get 200 status and valid typescript data?


Final thoughts

The most probable explanation is that a network intermediary device (like a firewall application) in your company's network is intercepting the cache-busted requests for the *.d.ts files. This is incorrectly deciding to send a 304 Not Modified response, preventing your browser/client from downloading the actual ts (typescript) text file.

After disabling the cache, the '.d.ts' file can be obtained normally.

But when I opened it, it was garbled. I'm not sure where the problem lies

Can access this particular node red via a browser using the localhost URL (I.e. actually open its editor on the server itself using a localhost or 127.0.0.1 url) do you get valid Typescript?

If yes, that would confirm your network is intercepting and replacing the response.

If you do have local access AND the data is still not correct, then perhaps the .ts files on your installation are corrupt.