denoland/deno · error · TypeError

Cannot access pointer: expected 'ArrayBuffer', 'SharedArrayB

Error message

Cannot access pointer: expected 'ArrayBuffer', 'SharedArrayBuffer', 'ArrayBufferView' or 'UnsafeCallbackPrototype', received ${typeof value}

What it means

Deno.UnsafePointer.of(value) extracts the memory address of a buffer-like value. It accepts an UnsafeCallback (returning its stored pointer), any ArrayBufferView (TypedArray/DataView, pointing at the first byte), or an ArrayBuffer/SharedArrayBuffer (wrapped in a Uint8Array internally). Any other input has no address to take, so a TypeError reporting the received typeof is thrown.

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 89f33cbef2)

Solutions

  1. For numeric addresses use Deno.UnsafePointer.create(0xn) instead of of()
  2. Wrap your data in a TypedArray before calling of(): Deno.UnsafePointer.of(new Uint8Array(buf))
  3. For UnsafeCallback instances pass the callback object itself (of() returns cb.pointer), never cb.pointer (a bigint)

Example fix

// before
const ptr = Deno.UnsafePointer.of(someBigintPointer); // TypeError

// after
const ptrObj = Deno.UnsafePointer.create(someBigintPointer);
// or, to get the address of actual bytes:
const ptrOfData = Deno.UnsafePointer.of(new Uint8Array(data));
Defensive patterns

Strategy: type-guard

Validate before calling

function isPointerSource(value) {
  return value instanceof ArrayBuffer || value instanceof SharedArrayBuffer ||
    ArrayBuffer.isView(value) ||
    (typeof value === "object" && value !== null && "pointer" in value && "definition" in value);
}

Type guard

function isPointerSource(
  value: unknown,
): value is ArrayBuffer | SharedArrayBuffer | ArrayBufferView | Deno.UnsafeCallback {
  return value instanceof ArrayBuffer || value instanceof SharedArrayBuffer ||
    ArrayBuffer.isView(value as ArrayBufferView) ||
    (typeof value === "object" && value !== null &&
      "pointer" in (value as object) && "definition" in (value as object));
}

Try / catch

try {
  const ptr = Deno.UnsafePointer.of(value);
} catch (err) {
  if (err instanceof TypeError && err.message.startsWith("Cannot access pointer")) {
    // value has no address: wrap bytes in a TypedArray, or use UnsafePointer.create for numeric addresses
  } else throw err;
}

Prevention

When it happens

Trigger: Passing a bigint or number holding a pointer value, a plain object, a string, null, or undefined to Deno.UnsafePointer.of(); also passing a Deno.UnsafePointerView instead of its underlying buffer.

Common situations: Confusing UnsafePointer.of (buffer to pointer) with UnsafePointer.create (bigint to pointer object); round-tripping a pointer value back through of(); passing a Web API object (Blob, Response) that is not backed by a contiguous buffer.

Related errors


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/2a2c15a799a39dbc. Report an issue: GitHub.