structuredClone() not supported in Function nodes

Hi,
I tried to use structuredClone() for deep-copy of objects within Function nodes, but get a runtime error:
image

Does anyone have a clue? This method works well in my developed custom nodes and seems cleaner than the JSON stringify/parse conversion. (Object.assign() and {...obj} spread are not relevant here since they only do a shallow copy)

Structured clone is nodejs 17+ i believe
try
RED.util.cloneMessage(object)
https://nodered.org/docs/api/modules/v/0.20.0/@node-red_util_util.html#.cloneMessage

2 Likes

Thanks,
Indeed, this has been released on Node JS 17.

I understand that Node-red framework tries to be backwards compatible for users with older Node-JS versions, but since I am able use it in my custom nodes, does it mean that the Function nodes run in some type of "compatibility sandbox"?

This isn't about backward compatibility; the Function node runs code inside a Sandbox that limits what globals are available. For example, you cannot use require amongst other things.

If node.js introduces a new global, we have to explicitly add it to the sandbox environment (if appropriate to do so). But that needs someone to raise the requirement to do so.

Got it. Thanks Nick

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.