{"record":{"id":"6744ccaa0bd46a57","repo":"perspective-dev/perspective","slug":"init-server-requires-a-wasm-source-or-a-wasm32-w","errorCode":null,"errorMessage":"init_server requires a wasm source or a {wasm32, wasm64} registration","messagePattern":"init_server requires a wasm source or a (.+?) registration","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"rust/perspective-js/src/ts/perspective.browser.ts","lineNumber":212,"sourceCode":"    if (is_wasm_source(wasm)) {\n        SERVER_REGISTRY = { sole: wasm, disable_stage_0 };\n        return;\n    }\n\n    // `WebAssembly.Module`'s lib type is structurally empty, so TypeScript\n    // can't negatively narrow this branch itself.\n    const registration = wasm as ServerWasmRegistration;\n    if (\n        registration.wasm32 !== undefined ||\n        registration.wasm64 !== undefined\n    ) {\n        SERVER_REGISTRY = {\n            wasm32: registration.wasm32,\n            wasm64: registration.wasm64,\n            disable_stage_0,\n        };\n    } else {\n        throw new Error(\n            \"init_server requires a wasm source or a {wasm32, wasm64} registration\",\n        );\n    }\n}\n\nlet GLOBAL_CLIENT_WASM: Promise<typeof psp>;\nlet GLOBAL_CLIENT_MODULE: Promise<WebAssembly.Module> | undefined;\n\nasync function compile_module(wasm: any): Promise<WebAssembly.Module> {\n    if (wasm instanceof WebAssembly.Module) {\n        return wasm;\n    }\n\n    if (typeof Response !== \"undefined\" && wasm instanceof Response) {\n        return WebAssembly.compileStreaming(wasm);\n    }\n\n    return WebAssembly.compile(wasm);","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/perspective-dev/perspective/blob/11c8238c0c9c0b9e490b5a6a2dc277afad1e980a/rust/perspective-js/src/ts/perspective.browser.ts#L194-L230","documentation":"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.","triggerScenarios":"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`.","commonSituations":"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.","solutions":["Pass the wasm source directly: `perspective.init_server(fetch('perspective-server.wasm'))`.","If passing a registration object, use the exact keys `wasm32` and/or `wasm64`: `init_server({ wasm32: () => fetch('...wasm') })`.","Log the argument before calling and verify at least one of `wasm32`/`wasm64` is defined (check for typos like `wasm_32`).","Check the perspective-js version docs — the accepted shapes are a single source or `{wasm32?, wasm64?}`."],"exampleFix":"// before\nperspective.init_server({ wasm: fetch(\"perspective-server.wasm\") });\n// after\nperspective.init_server({ wasm32: () => fetch(\"perspective-server.wasm\") });","handlingStrategy":"validation","validationCode":"function isValidServerRegistration(w) {\n  return w instanceof Response || w instanceof ArrayBuffer ||\n    typeof w === \"function\" ||\n    (w && typeof w === \"object\" && (w.wasm32 !== undefined || w.wasm64 !== undefined));\n}\nif (!isValidServerRegistration(arg)) throw new TypeError(\"init_server needs a wasm source or {wasm32, wasm64}\");","typeGuard":"function isWasmSource(w): w is Response | ArrayBuffer | (() => Promise<Response | ArrayBuffer>) {\n  return w instanceof Response || w instanceof ArrayBuffer || typeof w === \"function\";\n}","tryCatchPattern":"try {\n  perspective.init_server(arg);\n} catch (e) {\n  if (String(e.message).includes(\"wasm source or a {wasm32, wasm64}\")) {\n    console.error(\"Bad init_server argument:\", arg);\n  }\n  throw e;\n}","preventionTips":["Always pass either a fetch()/Response directly or an object keyed exactly `wasm32`/`wasm64`.","Wrap thunks in arrow functions: `wasm32: () => fetch(url)`.","Grep for legacy option keys (`wasm`, `source`) when upgrading versions.","Add a runtime assertion in your bootstrap before calling init_server."],"tags":["wasm","invalid-argument","initialization","browser"],"backgroundTag":"invalid-argument-value","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"}