zloirock/core-js · error · TypeError

Transfer option cannot be converted to a sequence

Error message

Transfer option cannot be converted to a sequence

What it means

TypeError thrown by tryToTransfer in the core-js structuredClone polyfill when the transfer option passed to structuredClone(value, { transfer }) is not an object that can be iterated as a sequence (per WebIDL it must be a sequence of transferable objects). Anything non-object — a string, number, null-ish wrapped value — fails the isObject check.

Source

Thrown at packages/core-js/modules/web.structured-clone.js:431

        createNonEnumerableProperty(cloned, 'cause', structuredCloneInternal(value.cause, map));
      }
      if (name === 'AggregateError') {
        cloned.errors = structuredCloneInternal(value.errors, map);
      } else if (name === 'SuppressedError') {
        cloned.error = structuredCloneInternal(value.error, map);
        cloned.suppressed = structuredCloneInternal(value.suppressed, map);
      } // break omitted
    case 'DOMException':
      if (ERROR_STACK_INSTALLABLE) {
        createNonEnumerableProperty(cloned, 'stack', structuredCloneInternal(value.stack, map));
      }
  }

  return cloned;
};

var tryToTransfer = function (rawTransfer, map) {
  if (!isObject(rawTransfer)) throw new TypeError('Transfer option cannot be converted to a sequence');

  var transfer = [];

  iterate(rawTransfer, function (value) {
    push(transfer, anObject(value));
  });

  var i = 0;
  var length = lengthOfArrayLike(transfer);
  var buffers = new Set();
  var value, type, C, transferred, canvas, context;

  while (i < length) {
    value = transfer[i++];
    type = classof(value);
    transferred = undefined;

    if (type === 'ArrayBuffer' ? setHas(buffers, value) : mapHas(map, value)) {

View on GitHub (pinned to 84e45fba09)

Solutions

  1. Always pass an array of transferable objects: { transfer: [buffer] }
  2. Wrap single transferables in an array before calling
  3. Validate the option is an array/object before invoking structuredClone

Example fix

// before
structuredClone(state, { transfer: buf }); // TypeError: Transfer option cannot be converted to a sequence
// after
structuredClone(state, { transfer: [buf] });
Defensive patterns

Strategy: validation

Validate before calling

function buildOptions(transfer) {
  if (transfer != null && !Array.isArray(transfer) && (typeof transfer !== 'object' || typeof transfer[Symbol.iterator] !== 'function')) {
    transfer = [transfer];
  }
  return { transfer };
}

Type guard

const isTransferSequence = (t) =>
  t != null && typeof t === 'object' && (Array.isArray(t) || typeof t[Symbol.iterator] === 'function');

Try / catch

try {
  return structuredClone(v, opts);
} catch (e) {
  if (e instanceof TypeError && /Transfer option cannot be converted/.test(e.message)) {
    return structuredClone(v, { transfer: [opts.transfer].flat().filter(Boolean) });
  }
  throw e;
}

Prevention

When it happens

Trigger: structuredClone(value, { transfer: 'abc' }) or { transfer: 42 } — a non-object transfer option; per spec a string is actually iterable, but the polyfill's isObject check rejects it with this TypeError before iterating.

Common situations: Dynamically building options and accidentally passing a single transferable instead of an array (transfer: buf instead of [buf]) combined with a primitive; typos like transfer: null; confused option shapes from older call sites.

Related errors


AI-assisted analysis of zloirock/core-js@84e45fba09 (2026-08-30). Data as JSON: /api/errors/e83d2bb78980de95. Report an issue: GitHub.