denoland/deno · error · TypeError
Cannot access pointer: expected 'ArrayBuffer'…
Error message
Cannot access pointer: expected 'ArrayBuffer', 'SharedArrayBuffer', 'ArrayBufferView' or 'UnsafeCallbackPrototype', received ${typeof value} What it means
Deno.UnsafePointer.of(value) converts a JS value to a raw FFI pointer. It accepts UnsafeCallback instances (using their registered pointer), ArrayBuffer views (TypedArray/DataView), and ArrayBuffer/SharedArrayBuffer. Any other value — number, bigint, string, plain object, null — throws this TypeError, with the received typeof interpolated.
Solutions
- Pass memory as a Uint8Array/DataView (ArrayBufferView) or the ArrayBuffer itself
- For numeric addresses use Deno.UnsafePointer.create(value) (bigint) to obtain a pointer object instead of passing the number to of()
- For callbacks, pass the Deno.UnsafeCallback instance; its .pointer is used automatically
- Convert plain arrays: new Uint8Array([...]) before the call
Example fix
// before const ptr = Deno.UnsafePointer.of(0x1000); // TypeError: received number // after const ptr = Deno.UnsafePointer.create(0x1000n); // wrap a numeric address const bufPtr = Deno.UnsafePointer.of(new Uint8Array([1, 2, 3])); // memory pointer
Defensive patterns
Strategy: type-guard
Type guard
function isPointerSource(value) {
return value instanceof Deno.UnsafeCallback ||
ArrayBuffer.isView(value) ||
value instanceof ArrayBuffer ||
value instanceof SharedArrayBuffer;
}
const ptr = isPointerSource(v)
? Deno.UnsafePointer.of(v)
: Deno.UnsafePointer.create(BigInt(v)); // numeric addresses Try / catch
try {
ptr = Deno.UnsafePointer.of(value);
} catch (err) {
if (err instanceof TypeError && err.message.startsWith("Cannot access pointer")) {
value = new Uint8Array(value); // coerce and retry once
ptr = Deno.UnsafePointer.of(value);
} else throw err;
} Prevention
- Always pass typed arrays or buffers across the FFI boundary, never numbers or plain objects
- Keep the two pointer APIs straight: of(memory) for buffers, create(bigint) for numeric addresses
- Validate with ArrayBuffer.isView() at wrapper boundaries
When it happens
Trigger: Deno.UnsafePointer.of(0x1000) or UnsafePointer.of(123n) (numeric addresses are not accepted here); passing a plain object, string, or null where FFI expects a buffer; passing a Web object like Blob instead of a Uint8Array; passing a plain Array instead of a typed array.
Common situations: Wrapping C functions that take void* + length; holding a numeric address from previous FFI calls and passing it where a buffer is required; interop code that sometimes receives arrays or objects; passing an UnsafePointerView instance instead of the underlying buffer.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- A chunk may only be either a string or an Uint8Array
- A key and certificate are required for `Deno.listenTls`
- AAD length exceeds i32::MAX
- buffer must be a TypedArray or a DataView
- callback must be a function
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/2a2c15a799a39dbc.
Report an issue: GitHub.
Appendix: source
Thrown at ext/ffi/00_ffi.js:258
let pointer;
if (ArrayBufferIsView(value)) {
if (value.length === 0) {
pointer = op_ffi_ptr_of_exact(value);
} else {
pointer = op_ffi_ptr_of(value);
}
} else if (isAnyArrayBuffer(value)) {
// `ArrayBuffer`/`SharedArrayBuffer` expose `byteLength`, not `length`, so
// wrap in a `Uint8Array` and measure that to detect the empty case (the
// `op`s require a view anyway).
const view = new Uint8Array(value);
if (TypedArrayPrototypeGetByteLength(view) === 0) {
pointer = op_ffi_ptr_of_exact(view);
} else {
pointer = op_ffi_ptr_of(view);
}
} else {
throw new TypeError(
`Cannot access pointer: expected 'ArrayBuffer', 'SharedArrayBuffer', 'ArrayBufferView' or 'UnsafeCallbackPrototype', received ${typeof value}`,
);
}
if (pointer) {
POINTER_TO_BUFFER_WEAK_MAP.set(pointer, value);
}
return pointer;
}
static offset(value, offset) {
return op_ffi_ptr_offset(value, offset);
}
static value(value) {
if (ObjectPrototypeIsPrototypeOf(UnsafeCallbackPrototype, value)) {
value = value.pointer;
}
return op_ffi_ptr_value(value);View on GitHub (pinned to 9ad36f7a2c)