perspective-dev/perspective · error · Error

init_server requires a wasm source or a

Error message

init_server requires a wasm source or a {wasm32, wasm64} registration

What it means

perspective-js's `init_server()` accepts either a single wasm source (Response/ArrayBuffer/thunk) or a registration object with `wasm32` and/or `wasm64` fields. It throws this error when the argument is neither: an object was passed, but it had no `wasm32` and no `wasm64` property, so the library has no server wasm to register. The type check happens at runtime because TypeScript cannot distinguish a bare wasm source from a registration object structurally.

Solutions

  1. Pass the wasm source directly: `perspective.init_server(fetch('perspective-server.wasm'))`.
  2. If passing a registration object, use the exact keys `wasm32` and/or `wasm64`: `init_server({ wasm32: () => fetch('...wasm') })`.
  3. Log the argument before calling and verify at least one of `wasm32`/`wasm64` is defined (check for typos like `wasm_32`).
  4. Check the perspective-js version docs — the accepted shapes are a single source or `{wasm32?, wasm64?}`.

Example fix

// before
perspective.init_server({ wasm: fetch("perspective-server.wasm") });
// after
perspective.init_server({ wasm32: () => fetch("perspective-server.wasm") });
Defensive patterns

Strategy: validation

Validate before calling

function isValidServerRegistration(w) {
  return w instanceof Response || w instanceof ArrayBuffer ||
    typeof w === "function" ||
    (w && typeof w === "object" && (w.wasm32 !== undefined || w.wasm64 !== undefined));
}
if (!isValidServerRegistration(arg)) throw new TypeError("init_server needs a wasm source or {wasm32, wasm64}");

Type guard

function isWasmSource(w): w is Response | ArrayBuffer | (() => Promise<Response | ArrayBuffer>) {
  return w instanceof Response || w instanceof ArrayBuffer || typeof w === "function";
}

Try / catch

try {
  perspective.init_server(arg);
} catch (e) {
  if (String(e.message).includes("wasm source or a {wasm32, wasm64}")) {
    console.error("Bad init_server argument:", arg);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling `perspective.init_server(obj)` where `obj` is an object lacking both `wasm32` and `wasm64` keys — e.g. `{ wasm: fetch(...) }`, `{ source: ... }`, `{}` — or passing a plain object where a fetch()/Response was expected. Also triggered by typos like `wasm_32` or `wasm64Url`.

Common situations: Renaming keys when migrating to the wasm32/wasm64 registration API; building the options object dynamically and both keys ending up undefined; copying example code but wrapping the fetch in an extra object; using an older registration shape `{ wasm: ... }` from a previous perspective version.

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


AI-assisted analysis of perspective-dev/perspective@11c8238c0c (2026-09-09). Data as JSON: /api/errors/6744ccaa0bd46a57. Report an issue: GitHub.

Appendix: source

Thrown at rust/perspective-js/src/ts/perspective.browser.ts:212

    if (is_wasm_source(wasm)) {
        SERVER_REGISTRY = { sole: wasm, disable_stage_0 };
        return;
    }

    // `WebAssembly.Module`'s lib type is structurally empty, so TypeScript
    // can't negatively narrow this branch itself.
    const registration = wasm as ServerWasmRegistration;
    if (
        registration.wasm32 !== undefined ||
        registration.wasm64 !== undefined
    ) {
        SERVER_REGISTRY = {
            wasm32: registration.wasm32,
            wasm64: registration.wasm64,
            disable_stage_0,
        };
    } else {
        throw new Error(
            "init_server requires a wasm source or a {wasm32, wasm64} registration",
        );
    }
}

let GLOBAL_CLIENT_WASM: Promise<typeof psp>;
let GLOBAL_CLIENT_MODULE: Promise<WebAssembly.Module> | undefined;

async function compile_module(wasm: any): Promise<WebAssembly.Module> {
    if (wasm instanceof WebAssembly.Module) {
        return wasm;
    }

    if (typeof Response !== "undefined" && wasm instanceof Response) {
        return WebAssembly.compileStreaming(wasm);
    }

    return WebAssembly.compile(wasm);

View on GitHub (pinned to 11c8238c0c)