{"record":{"id":"2473039fba8f26fb","repo":"perspective-dev/perspective","slug":"perspective-js-client-wasm-has-not-been-compiled-y","errorCode":null,"errorMessage":"perspective-js client wasm has not been compiled yet — call `init_client(...)` or `perspective.worker()` before `getCompiledClientWasm()`.","messagePattern":"perspective-js client wasm has not been compiled yet — call `init_client\\(\\.\\.\\.\\)` or `perspective\\.worker\\(\\)` before `getCompiledClientWasm\\(\\)`\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"rust/perspective-js/src/ts/perspective.browser.ts","lineNumber":321,"sourceCode":" * ```javascript\n * const mod = await perspective.getCompiledClientWasm();\n * worker.postMessage({ kind: \"init\", clientWasm: mod }, [port]);\n * ```\n */\nexport async function getCompiledClientWasm(): Promise<WebAssembly.Module> {\n    if (GLOBAL_CLIENT_MODULE !== undefined) {\n        return GLOBAL_CLIENT_MODULE;\n    }\n\n    const viewer_class: any = customElements.get(\"perspective-viewer\");\n    if (viewer_class?.__wasm_client_module__) {\n        GLOBAL_CLIENT_MODULE = Promise.resolve(\n            viewer_class.__wasm_client_module__,\n        );\n        return GLOBAL_CLIENT_MODULE;\n    }\n\n    throw new Error(\n        \"perspective-js client wasm has not been compiled yet — call \" +\n            \"`init_client(...)` or `perspective.worker()` before \" +\n            \"`getCompiledClientWasm()`.\",\n    );\n}\n\nfunction get_server() {\n    if (SERVER_REGISTRY === undefined) {\n        throw new Error(\"Missing perspective-server.wasm\");\n    }\n\n    if (GLOBAL_SERVER_WASM === undefined) {\n        GLOBAL_SERVER_WASM = select_server_wasm(SERVER_REGISTRY);\n    }\n\n    return GLOBAL_SERVER_WASM.then((x) =>\n        x instanceof WebAssembly.Module ? x : x.slice(0),\n    );","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/perspective-dev/perspective/blob/11c8238c0c9c0b9e490b5a6a2dc277afad1e980a/rust/perspective-js/src/ts/perspective.browser.ts#L303-L339","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Call and await `perspective.init_client(fetch('perspective-client.wasm'))` before `getCompiledClientWasm()`.","Alternatively trigger `perspective.worker()` first, which compiles and caches the module.","If you mount a `<perspective-viewer>`, wait until it is defined and its wasm has loaded before calling.","Reorder bootstrap: `await init_client(...)` (or worker creation) → then `const mod = await perspective.getCompiledClientWasm()`."],"exampleFix":"// before\nconst mod = await perspective.getCompiledClientWasm(); // throws\n// after\nawait perspective.init_client(fetch(\"perspective-client.wasm\"));\nconst mod = await perspective.getCompiledClientWasm();","handlingStrategy":"try-catch","validationCode":"let moduleReady = false;\n// set moduleReady = true after `await perspective.init_client(...)` resolves\nif (!moduleReady) await perspective.init_client(fetch(\"perspective-client.wasm\"));\nconst mod = await perspective.getCompiledClientWasm();","typeGuard":"function clientCompiled(): boolean {\n  const viewer: any = customElements.get(\"perspective-viewer\");\n  return moduleReady || !!viewer?.__wasm_client_module__;\n}","tryCatchPattern":"try {\n  const mod = await perspective.getCompiledClientWasm();\n} catch (e) {\n  if (String(e.message).includes(\"has not been compiled yet\")) {\n    await perspective.init_client(fetch(\"perspective-client.wasm\"));\n    const mod = await perspective.getCompiledClientWasm();\n  } else throw e;\n}","preventionTips":["Await `init_client(...)` before requesting the compiled module — an unresolved init still counts as not compiled.","Centralize wasm initialization in one bootstrap function that resolves before any worker messaging.","Guard custom Worker flows: always call init_client or perspective.worker() before getCompiledClientWasm().","Beware HMR resetting module state; re-run init on reload."],"tags":["wasm","initialization","call-order","browser"],"backgroundTag":"module-init-failed","analyzedSha":"11c8238c0c9c0b9e490b5a6a2dc277afad1e980a","analyzedAt":"2026-09-09T00:35:19.377Z","contentChangedAt":"2026-09-09T00:35:19.377Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}