Explore Bato Web Agency Webflow Certified Partner Profile Explore Bato Web Agency Webflow Certified Partner Profile

DataCloneError: The object could not be cloned

Illustration without a description Illustration without a description

The operation tried to copy a value that the structured clone algorithm cannot handle. Start with the argument passed to postMessage(), structuredClone() or the IndexedDB write. Functions and DOM nodes can be buried inside an otherwise ordinary record.

 

Build a payload with the data the receiver actually needs. Keep functions and elements in the context that owns them, and transfer supported buffers when appropriate. Preserve the types the receiver expects. The example shows that a Date can survive structured cloning as a Date.

 

A structured clone can preserve a Date as a Date. If a small payload succeeds while the real one fails, narrow down the nested field the receiver needs and replace only the unsupported value.

 

const source = { id: 1, createdAt: new Date() }; const copy = structuredClone(source); console.log(copy.createdAt instanceof Date);

 

Reduce the failing value one property at a time and test the smallest payload that still throws DataCloneError.