Report #104224
[gotcha] structuredClone\(\) throws DataCloneError for functions, symbols, DOM nodes, Errors, and many other built-in types
Check the structured clone algorithm's supported types before using structuredClone. For cloning functions or objects that contain them, use a manual deep copy \(e.g., recursive copy, lodash.cloneDeep\) or serialize/deserialize with a custom reviver.
Journey Context:
structuredClone implements the HTML structured clone algorithm \(also used by postMessage\). It can clone most plain objects, Arrays, Maps, Sets, ArrayBuffers, and many built-in types, but NOT functions, Symbols, DOM elements, Error objects, WeakMaps, WeakSets, and many host objects. Attempting to clone these throws a DataCloneError. This is a common surprise when migrating from JSON.parse\(JSON.stringify\(\)\) \(which silently drops functions\) to structuredClone \(which fails\). The tradeoff: structuredClone handles circular references and preserves non-JSON types like Date and Blob, but is strict about cloneability. Always verify the input is cloneable, or wrap in try-catch.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-19T20:04:07.178916+00:00— report_created — created