zloirock/core-js · error · TypeError
ArrayBuffer expected
Error message
ArrayBuffer expected
What it means
core-js's arrayBufferByteLength helper returns the byteLength of an ArrayBuffer, falling back to a manual implementation when the native getter is unavailable. In the fallback it first verifies the argument's internal class is 'ArrayBuffer'; otherwise it throws 'TypeError: ArrayBuffer expected'. The spec step this mirrors is RequireInternalSlot(O, [[ArrayBufferData]]), so it fires when you pass something that is not an ArrayBuffer (note shared ArrayBuffers are rejected elsewhere).
Source
Thrown at packages/core-js/internals/array-buffer-byte-length.js:13
'use strict';
var globalThis = require('../internals/global-this');
var uncurryThisAccessor = require('../internals/function-uncurry-this-accessor');
var classof = require('../internals/classof-raw');
var ArrayBuffer = globalThis.ArrayBuffer;
var TypeError = globalThis.TypeError;
// Includes
// - Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
// - If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
module.exports = ArrayBuffer && uncurryThisAccessor(ArrayBuffer.prototype, 'byteLength', 'get') || function (O) {
if (classof(O) !== 'ArrayBuffer') throw new TypeError('ArrayBuffer expected');
return O.byteLength;
};
View on GitHub (pinned to 84e45fba09)
Solutions
- Pass an actual ArrayBuffer instance (use typedArray.buffer when starting from a typed array).
- Verify the value with Object.prototype.toString.call(v) === '[object ArrayBuffer]' before calling.
- If you hold a SharedArrayBuffer, switch to a regular ArrayBuffer — the spec explicitly rejects shared buffers here.
- Ensure a consistent core-js version/config; mismatched polyfill setups can route to the fallback path unexpectedly.
Example fix
// before var len = arrayBufferByteLength(typedArray); // TypeError: ArrayBuffer expected // after var len = arrayBufferByteLength(typedArray.buffer);
Defensive patterns
Strategy: validation
Validate before calling
function isArrayBuffer(v){ return Object.prototype.toString.call(v) === '[object ArrayBuffer]'; }
if (!isArrayBuffer(input)) throw new TypeError('expected an ArrayBuffer'); Type guard
function isArrayBuffer(v){ return Object.prototype.toString.call(v) === '[object ArrayBuffer]'; } Try / catch
try { len = arrayBufferByteLength(input); } catch (e) { if (e instanceof TypeError) len = fallbackLength(input); else throw e; } Prevention
- Always pass .buffer when starting from a typed array.
- Remember SharedArrayBuffer is rejected here.
- In polyfilled/legacy environments, validate class with Object.prototype.toString before calling.
- Pin a single core-js version to keep fallback behavior consistent.
When it happens
Trigger: Calling arrayBufferByteLength(O) with a non-ArrayBuffer value: a DataView, a typed array, a SharedArrayBuffer (in builds where the native getter path is skipped), a plain object, or undefined/null.
Common situations: Polyfilled environments (older engines without ArrayBuffer.prototype byteLength accessor) where the fallback path runs; code that confuses a typed array for its .buffer; passing a SharedArrayBuffer by mistake; transitive failure through other core-js polyfills (e.g. ArrayBuffer.prototype.slice, DataView internals) given a wrong argument.
Related errors
- Target is not a typed array
- Object already initialized
- Cannot convert a Symbol value to a number
- Promise can't be resolved itself
- Symbol is not a constructor
AI-assisted analysis of zloirock/core-js@84e45fba09 (2026-08-30).
Data as JSON: /api/errors/bfa102b848a8442e.
Report an issue: GitHub.