zloirock/core-js · error · DOMException
DATA_CLONE_ERROR
DATA_CLONE_ERROR
Error message
Uncloneable type: <type> (dynamic: 'Uncloneable type: ' + type)
What it means
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.
Source
Thrown at packages/core-js/modules/web.structured-clone.js:116
// Chrome 82+, Safari 14.1+, Deno 1.11+
// Chrome 78-81 implementation swaps `.name` and `.message` of cloned `DOMException`
// Chrome returns `null` if cloned object contains multiple references to one error
// Safari 14.1 implementation doesn't clone some `RegExp` flags, so requires a workaround
// Safari implementation can't clone errors
// Deno 1.2-1.10 implementations too naive
// NodeJS 16.0+ does not have `PerformanceMark` constructor
// NodeJS <17.2 structured cloning implementation from `performance.mark` is too naive
// and can't clone, for example, `RegExp` or some boxed primitives
// https://github.com/nodejs/node/issues/40840
// no one of those implementations supports new (html/5749) error cloning semantic
var structuredCloneFromMark = !nativeStructuredClone && checkBasicSemantic(function (value) {
return new PerformanceMark(PERFORMANCE_MARK, { detail: value }).detail;
});
var nativeRestrictedStructuredClone = checkBasicSemantic(nativeStructuredClone) || structuredCloneFromMark;
var throwUncloneable = function (type) {
throw new DOMException('Uncloneable type: ' + type, DATA_CLONE_ERROR);
};
var throwUnpolyfillable = function (type, action) {
throw new DOMException((action || 'Cloning') + ' of ' + type + ' cannot be properly polyfilled in this engine', DATA_CLONE_ERROR);
};
var tryNativeRestrictedStructuredClone = function (value, type) {
if (!nativeRestrictedStructuredClone) throwUnpolyfillable(type);
return nativeRestrictedStructuredClone(value);
};
var createDataTransfer = function () {
var dataTransfer;
try {
dataTransfer = new globalThis.DataTransfer();
} catch (error) {
try {
dataTransfer = new globalThis.ClipboardEvent('').clipboardData;View on GitHub (pinned to 84e45fba09)
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
Example fix
// before
const copy = structuredClone({ cb: handleClick, data: [1, 2] }); // DOMException: Uncloneable type: Function
// after
const { cb, ...cloneable } = { cb: handleClick, data: [1, 2] };
const copy = structuredClone(cloneable); Defensive patterns
Strategy: try-catch
Validate before calling
function isCloneable(v, seen = new Set()) {
if (v === null || typeof v !== 'object' && typeof v !== 'function' && typeof v !== 'symbol') return true;
if (typeof v === 'function' || typeof v === 'symbol' || v instanceof WeakMap || v instanceof WeakSet) return false;
if (seen.has(v)) return true;
seen.add(v);
return Object.keys(v).every(k => isCloneable(v[k], seen));
} Type guard
const isCloneableValue = (v) => v === null || ['undefined','boolean','number','string','bigint'].includes(typeof v) || (typeof v === 'object' && !(v instanceof WeakMap) && !(v instanceof WeakSet) && !(typeof Node !== 'undefined' && v instanceof Node));
Try / catch
let copy;
try {
copy = structuredClone(value);
} catch (e) {
if (e.name === 'DataCloneError' && /Uncloneable type/.test(e.message)) {
copy = JSON.parse(JSON.stringify(value, (k, v) => typeof v === 'function' || typeof v === 'symbol' ? undefined : v));
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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'.
Common situations: 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.
Related errors
- ArrayBuffer expected
- Target is not a typed array
- Object already initialized
- String should only contain hex characters
- Failed to parse number at: ${i}
AI-assisted analysis of zloirock/core-js@84e45fba09 (2026-08-30).
Data as JSON: /api/errors/db96e44edd525cfb.
Report an issue: GitHub.