sindresorhus/is · error · TypeError
Expected value which is `SharedArrayBuffer`, received value
Error message
Expected value which is `SharedArrayBuffer`, received value of type `${is(value)}`. What it means
Thrown by `assert.sharedArrayBuffer()` (assertSharedArrayBuffer at source/index.ts:1888) when the value is not a `SharedArrayBuffer` instance. Regular `ArrayBuffer`, typed arrays, and DataViews all fail — the two buffer types are distinct classes. This assertion also fails when `SharedArrayBuffer` itself is unavailable in the environment.
Source
Thrown at source/index.ts:1890
throw new TypeError(message ?? typeErrorMessage('RegExp', value));
}
}
export function assertSafeInteger(value: unknown, message?: string): asserts value is number {
if (!isSafeInteger(value)) {
throw new TypeError(message ?? typeErrorMessage('safe integer', value));
}
}
export function assertSet<T = unknown>(value: unknown, message?: string): asserts value is Set<T> {
if (!isSet(value)) {
throw new TypeError(message ?? typeErrorMessage('Set', value));
}
}
export function assertSharedArrayBuffer(value: unknown, message?: string): asserts value is SharedArrayBuffer {
if (!isSharedArrayBuffer(value)) {
throw new TypeError(message ?? typeErrorMessage('SharedArrayBuffer', value));
}
}
export function assertString(value: unknown, message?: string): asserts value is string {
if (!isString(value)) {
throw new TypeError(message ?? typeErrorMessage('string', value));
}
}
export function assertSymbol(value: unknown, message?: string): asserts value is symbol {
if (!isSymbol(value)) {
throw new TypeError(message ?? typeErrorMessage('symbol', value));
}
}
export function assertTruthy<T>(value: T | Falsy, message?: string): asserts value is T {
if (!isTruthy(value)) {
throw new TypeError(message ?? typeErrorMessage('truthy', value));View on GitHub ↗ (pinned to 7821031c66)
Solutions
- Allocate the buffer as shared: `new SharedArrayBuffer(size)` instead of `new ArrayBuffer(size)`.
- In browsers, enable cross-origin isolation with COOP/COEP headers so SharedArrayBuffer exists.
- If a value is a typed array, pass `view.buffer` only when the view was created over a SharedArrayBuffer; otherwise use `assert.arrayBuffer()`.
Example fix
// before const buf = new ArrayBuffer(1024); assert.sharedArrayBuffer(buf); // after const buf = new SharedArrayBuffer(1024); assert.sharedArrayBuffer(buf);
Defensive patterns
Strategy: validation
Validate before calling
if (typeof SharedArrayBuffer === 'undefined') {
throw new Error('SharedArrayBuffer unavailable (needs cross-origin isolation)');
}
if (!(value instanceof SharedArrayBuffer)) {
throw new TypeError('Expected a SharedArrayBuffer');
} Type guard
function isSharedArrayBuffer(value: unknown): value is SharedArrayBuffer {
return typeof SharedArrayBuffer !== 'undefined' && Object.prototype.toString.call(value) === '[object SharedArrayBuffer]';
} Try / catch
try {
assert.sharedArrayBuffer(value);
} catch (error) {
if (error instanceof TypeError) {
// likely a plain ArrayBuffer, or SAB is disabled in this environment
}
throw error;
} Prevention
- Check environment support first — browsers require COOP/COEP headers for SharedArrayBuffer to exist
- Don't confuse ArrayBuffer with SharedArrayBuffer; they are distinct types and postMessage/transfer semantics differ
- Guard worker-message handlers, since buffers arriving via postMessage may be either kind
When it happens
Trigger: Calling `assert.sharedArrayBuffer(value)` with a plain `ArrayBuffer`, a `Uint8Array` (a view, not a buffer), or in browsers where SharedArrayBuffer is disabled because the page is not cross-origin isolated (missing COOP/COEP headers).
Common situations: Browsers hide SharedArrayBuffer unless the page sends `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp` (post-Spectre mitigation), so worker code that works in Node fails in the browser; passing a typed array's `.buffer` which is an ArrayBuffer unless explicitly allocated shared.
Related errors
- Expected value which is `Class`, received value of type `${i
- Expected value which is `empty map`, received value of type
- Expected value which is `empty object`, received value of ty
- Expected value which is `empty set`, received value of type
- Expected value which is `empty string`, received value of ty
AI-assisted analysis of sindresorhus/is@7821031c66 (2026-07-31).
Data as JSON: /data/errors/e0ca2cf887a21fe6.json.
Report an issue: GitHub ↗.