JavaScript structuredClone silently drops custom Error subclasses and extra properties; functions throw "DataCloneError: f(){} could not be cloned."
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.