# structuredClone() not supported in Function nodes

**URL:** <https://discourse.nodered.org/t/structuredclone-not-supported-in-function-nodes/73425>\
**Category:** General\
**Created:** [9 January 2023 19:01 UTC](https://discourse.nodered.org/t/structuredclone-not-supported-in-function-nodes/73425 "2023-01-09T19:01:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![omrid](https://avatars.discourse-cdn.com/v4/letter/o/77aa72/32.png) [@omrid](https://discourse.nodered.org/u/omrid)\
**Post date:** [9 January 2023 19:01 UTC](https://discourse.nodered.org/t/structuredclone-not-supported-in-function-nodes/73425/1 "2023-01-09T19:01:12Z")

</div>

Hi,  
I tried to use structuredClone() for deep-copy of objects within Function nodes, but get a runtime error:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/f/ff70fc2cc9a5d4e96eae8f3a11db68d7a2e15e42.png)

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)

---

<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:** [9 January 2023 19:29 UTC](https://discourse.nodered.org/t/structuredclone-not-supported-in-function-nodes/73425/2 "2023-01-09T19:29:24Z")

</div>

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](https://nodered.org/docs/api/modules/v/0.20.0/@node-red_util_util.html#.cloneMessage)

---

<div class="post-metadata">

**Author:** ![omrid](https://avatars.discourse-cdn.com/v4/letter/o/77aa72/32.png) [@omrid](https://discourse.nodered.org/u/omrid)\
**Post date:** [10 January 2023 15:39 UTC](https://discourse.nodered.org/t/structuredclone-not-supported-in-function-nodes/73425/3 "2023-01-10T15:39:04Z")

</div>

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"?

---

<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 January 2023 15:51 UTC](https://discourse.nodered.org/t/structuredclone-not-supported-in-function-nodes/73425/4 "2023-01-10T15:51:57Z")

</div>

> [@omrid](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![omrid](https://avatars.discourse-cdn.com/v4/letter/o/77aa72/32.png) [@omrid](https://discourse.nodered.org/u/omrid)\
**Post date:** [10 January 2023 16:27 UTC](https://discourse.nodered.org/t/structuredclone-not-supported-in-function-nodes/73425/5 "2023-01-10T16:27:12Z")

</div>

Got it. Thanks Nick

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [11 March 2023 16:27 UTC](https://discourse.nodered.org/t/structuredclone-not-supported-in-function-nodes/73425/6 "2023-03-11T16:27:52Z")

</div>

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