{"record":{"id":"db96e44edd525cfb","repo":"zloirock/core-js","slug":"data-clone-error","errorCode":"DATA_CLONE_ERROR","errorMessage":"Uncloneable type: <type> (dynamic: 'Uncloneable type: ' + type)","messagePattern":"Uncloneable type: <type> \\(dynamic: 'Uncloneable type: ' \\+ type\\)","errorType":"exception","errorClass":"DOMException","httpStatus":null,"severity":"error","filePath":"packages/core-js/modules/web.structured-clone.js","lineNumber":116,"sourceCode":"// Chrome 82+, Safari 14.1+, Deno 1.11+\n// Chrome 78-81 implementation swaps `.name` and `.message` of cloned `DOMException`\n// Chrome returns `null` if cloned object contains multiple references to one error\n// Safari 14.1 implementation doesn't clone some `RegExp` flags, so requires a workaround\n// Safari implementation can't clone errors\n// Deno 1.2-1.10 implementations too naive\n// NodeJS 16.0+ does not have `PerformanceMark` constructor\n// NodeJS <17.2 structured cloning implementation from `performance.mark` is too naive\n// and can't clone, for example, `RegExp` or some boxed primitives\n// https://github.com/nodejs/node/issues/40840\n// no one of those implementations supports new (html/5749) error cloning semantic\nvar structuredCloneFromMark = !nativeStructuredClone && checkBasicSemantic(function (value) {\n  return new PerformanceMark(PERFORMANCE_MARK, { detail: value }).detail;\n});\n\nvar nativeRestrictedStructuredClone = checkBasicSemantic(nativeStructuredClone) || structuredCloneFromMark;\n\nvar throwUncloneable = function (type) {\n  throw new DOMException('Uncloneable type: ' + type, DATA_CLONE_ERROR);\n};\n\nvar throwUnpolyfillable = function (type, action) {\n  throw new DOMException((action || 'Cloning') + ' of ' + type + ' cannot be properly polyfilled in this engine', DATA_CLONE_ERROR);\n};\n\nvar tryNativeRestrictedStructuredClone = function (value, type) {\n  if (!nativeRestrictedStructuredClone) throwUnpolyfillable(type);\n  return nativeRestrictedStructuredClone(value);\n};\n\nvar createDataTransfer = function () {\n  var dataTransfer;\n  try {\n    dataTransfer = new globalThis.DataTransfer();\n  } catch (error) {\n    try {\n      dataTransfer = new globalThis.ClipboardEvent('').clipboardData;","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/zloirock/core-js/blob/84e45fba098dd3a177d5cf2247d06ab8e98d3790/packages/core-js/modules/web.structured-clone.js#L98-L134","documentation":"DOMException with name DATA_CLONE_ERROR thrown by core-js's structuredClone polyfill when the value contains a type that cannot be cloned at all (e.g. functions, DOM nodes, Symbols, WeakMap). The internal throwUncloneable helper is invoked by structuredCloneInternal when it encounters such a type during the recursive clone.","triggerScenarios":"structuredClone(value) where value, or anything reachable from it, is an uncloneable type: a Function, Symbol, WeakMap/WeakSet, DOM Node, or a property getter returning such. Example: structuredClone({ fn: () => {} }) throws 'Uncloneable type: Function'.","commonSituations":"Cloning state objects that accidentally capture callbacks or class methods; deep-cloning React props or config objects containing event handlers; cloning objects holding Symbols as keys; using structuredClone as a cheap deep-clone for arbitrary JS data.","solutions":["Strip functions, Symbols, WeakMaps and other uncloneable values from the object before cloning","Use JSON.parse(JSON.stringify(...)) or a library deep-clone for plain data instead of structuredClone","Write a replacer/sanitizer that walks the object and removes non-cloneable members","Wrap the call in try/catch on DATA_CLONE_ERROR and fall back to a manual copy"],"exampleFix":"// before\nconst copy = structuredClone({ cb: handleClick, data: [1, 2] }); // DOMException: Uncloneable type: Function\n// after\nconst { cb, ...cloneable } = { cb: handleClick, data: [1, 2] };\nconst copy = structuredClone(cloneable);","handlingStrategy":"try-catch","validationCode":"function isCloneable(v, seen = new Set()) {\n  if (v === null || typeof v !== 'object' && typeof v !== 'function' && typeof v !== 'symbol') return true;\n  if (typeof v === 'function' || typeof v === 'symbol' || v instanceof WeakMap || v instanceof WeakSet) return false;\n  if (seen.has(v)) return true;\n  seen.add(v);\n  return Object.keys(v).every(k => isCloneable(v[k], seen));\n}","typeGuard":"const isCloneableValue = (v) =>\n  v === null || ['undefined','boolean','number','string','bigint'].includes(typeof v) ||\n  (typeof v === 'object' && !(v instanceof WeakMap) && !(v instanceof WeakSet) && !(typeof Node !== 'undefined' && v instanceof Node));","tryCatchPattern":"let copy;\ntry {\n  copy = structuredClone(value);\n} catch (e) {\n  if (e.name === 'DataCloneError' && /Uncloneable type/.test(e.message)) {\n    copy = JSON.parse(JSON.stringify(value, (k, v) => typeof v === 'function' || typeof v === 'symbol' ? undefined : v));\n  } else throw e;\n}","preventionTips":["Keep state objects free of functions and DOM references","Use plain serializable data for anything you clone","Strip Symbol-keyed properties before cloning","Prefer a deep-clone library for arbitrary objects"],"tags":["structured-clone","domexception","data-clone-error","polyfill"],"backgroundTag":"structured-clone-uncloneable-type","analyzedSha":"84e45fba098dd3a177d5cf2247d06ab8e98d3790","analyzedAt":"2026-08-30T20:36:10.323Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}