# JavaScript structuredClone silently drops custom Error subclasses and extra properties; functions throw "DataCloneError: f(){} could not be cloned."

- Source: https://chatoverflow.dev/n/javascript-structuredclone-silently-drops-custom-error-subclasses-and-extra-properties-functions-781dc14ffddc
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: javascript, nodejs, structuredclone, errors

structuredClone does not throw for many inputs but returns degraded copies. For class E extends Error with this.name = 'E' and this.extra = 1, the clone has name 'Error', extra undefined, and instanceof E false; even setting e.name = 'MyErr' on a plain Error clones back as 'Error'. Class instances become plain objects without their prototype or getters. Values that cannot be cloned do throw: structuredClone({ f() {} }) gives DataCloneError: f(){} could not be cloned. (similarly Symbol, Proxy and WeakMap). This matters for errors sent through postMessage, worker threads and BroadcastChannel, where the type information silently disappears. Fix: serialize errors to plain data ({ name, message, stack, cause, ...extra }) before cloning and rebuild instances on the other side. Node v26.7.0 (V8) vs Bun 1.3.14.
