perspective-dev/perspective · error · Error

perspective-js client wasm has not been compiled yet — call…

Error message

perspective-js client wasm has not been compiled yet — call `init_client(...)` or `perspective.worker()` before `getCompiledClientWasm()`.

What it means

`getCompiledClientWasm()` returns the compiled `WebAssembly.Module` for the perspective-js client runtime so it can be structured-cloned to a Worker. The module is only produced by `init_client()` (via `compilerize`) or reused from an initialized `<perspective-viewer>`. If neither has happened — no compiled module cached and no viewer with `__wasm_client_module__` — the function throws telling you to initialize the client wasm first.

Solutions

  1. Call and await `perspective.init_client(fetch('perspective-client.wasm'))` before `getCompiledClientWasm()`.
  2. Alternatively trigger `perspective.worker()` first, which compiles and caches the module.
  3. If you mount a `<perspective-viewer>`, wait until it is defined and its wasm has loaded before calling.
  4. Reorder bootstrap: `await init_client(...)` (or worker creation) → then `const mod = await perspective.getCompiledClientWasm()`.

Example fix

// before
const mod = await perspective.getCompiledClientWasm(); // throws
// after
await perspective.init_client(fetch("perspective-client.wasm"));
const mod = await perspective.getCompiledClientWasm();
Defensive patterns

Strategy: try-catch

Validate before calling

let moduleReady = false;
// set moduleReady = true after `await perspective.init_client(...)` resolves
if (!moduleReady) await perspective.init_client(fetch("perspective-client.wasm"));
const mod = await perspective.getCompiledClientWasm();

Type guard

function clientCompiled(): boolean {
  const viewer: any = customElements.get("perspective-viewer");
  return moduleReady || !!viewer?.__wasm_client_module__;
}

Try / catch

try {
  const mod = await perspective.getCompiledClientWasm();
} catch (e) {
  if (String(e.message).includes("has not been compiled yet")) {
    await perspective.init_client(fetch("perspective-client.wasm"));
    const mod = await perspective.getCompiledClientWasm();
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `await perspective.getCompiledClientWasm()` before any of: `init_client(...)` completing compilation, `perspective.worker()` being invoked, or a `<perspective-viewer>` element being defined with its wasm loaded. Also calling it while an in-flight `init_client(fetch(...))` promise has not resolved.

Common situations: Posting the module to a Worker in an app bootstrap sequence before wasm initialization awaits; calling from a separate module whose import ordering differs from init ordering; writing a custom worker flow that skips `perspective.worker()`; hot-module reloads clearing module state while init code no longer runs.

Related errors


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

Appendix: source

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

 * ```javascript
 * const mod = await perspective.getCompiledClientWasm();
 * worker.postMessage({ kind: "init", clientWasm: mod }, [port]);
 * ```
 */
export async function getCompiledClientWasm(): Promise<WebAssembly.Module> {
    if (GLOBAL_CLIENT_MODULE !== undefined) {
        return GLOBAL_CLIENT_MODULE;
    }

    const viewer_class: any = customElements.get("perspective-viewer");
    if (viewer_class?.__wasm_client_module__) {
        GLOBAL_CLIENT_MODULE = Promise.resolve(
            viewer_class.__wasm_client_module__,
        );
        return GLOBAL_CLIENT_MODULE;
    }

    throw new Error(
        "perspective-js client wasm has not been compiled yet — call " +
            "`init_client(...)` or `perspective.worker()` before " +
            "`getCompiledClientWasm()`.",
    );
}

function get_server() {
    if (SERVER_REGISTRY === undefined) {
        throw new Error("Missing perspective-server.wasm");
    }

    if (GLOBAL_SERVER_WASM === undefined) {
        GLOBAL_SERVER_WASM = select_server_wasm(SERVER_REGISTRY);
    }

    return GLOBAL_SERVER_WASM.then((x) =>
        x instanceof WebAssembly.Module ? x : x.slice(0),
    );

View on GitHub (pinned to 11c8238c0c)