{"record":{"id":"53ff35dcb3707336","repo":"ruvnet/ruflo","slug":"failed-to-load-wasm-module","errorCode":null,"errorMessage":"Failed to load WASM module","messagePattern":"Failed to load WASM module","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ruflo/src/ruvocal/src/lib/stores/wasmMcp.ts","lineNumber":84,"sourceCode":"// Request ID counter\nlet requestId = 0;\n\n/**\n * Initialize the WASM MCP server\n */\nexport async function initWasmMcp(): Promise<boolean> {\n\tif (!browser) return false;\n\n\tconst state = get(wasmMcpState);\n\tif (state.loaded || state.loading) return state.loaded;\n\n\twasmMcpState.update((s) => ({ ...s, loading: true, error: null }));\n\n\ttry {\n\t\t// Load WASM module\n\t\tconst wasm = await loadWasm();\n\t\tif (!wasm) {\n\t\t\tthrow new Error(\"Failed to load WASM module\");\n\t\t}\n\n\t\t// Create MCP server and gallery instances\n\t\tconst mcpServer = new wasm.WasmMcpServer();\n\t\tconst gallery = new wasm.WasmGallery();\n\n\t\t// Initialize the MCP server\n\t\tconst initResponse = callMcpInternal(mcpServer, \"initialize\", {\n\t\t\tprotocolVersion: \"2024-11-05\",\n\t\t\tclientInfo: { name: \"ruvocal-ui\", version: \"1.0.0\" },\n\t\t});\n\n\t\tif (initResponse.error) {\n\t\t\tthrow new Error(`MCP initialization failed: ${initResponse.error.message}`);\n\t\t}\n\n\t\t// Load persisted filesystem state from IndexedDB\n\t\tawait syncFromIndexedDB(mcpServer);","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/ruflo/src/ruvocal/src/lib/stores/wasmMcp.ts#L66-L102","documentation":"Thrown by initWasmMcp() (browser-only) when loadWasm() resolves to a falsy value, before any MCP server is constructed. The WASM module is expected to expose WasmMcpServer and WasmGallery constructors; a falsy return means the module never loaded or was not the expected export surface.","triggerScenarios":"Calling initWasmMcp() during SSR (the browser guard returns false earlier, so this path is browser-only), the WASM .wasm/.js glue asset 404s or fails to instantiate, the environment lacks WebAssembly support, or loadWasm() swallowed an instantiation error and returned null.","commonSituations":"Build did not emit the WASM asset to the expected path; CSP blocks wasm-unsafe-eval or the blob/StreamingInstantiate path; an older browser/worker context without WebAssembly; a misconfigured base path so the importer resolves to an HTML 404 page.","solutions":["Open the browser devtools Network tab and confirm the .wasm asset loads with 200 and application/wasm.","Check the Console for an instantiation/CSP error that loadWasm() may have caught and converted to a null return.","Verify Content-Security-Policy includes 'wasm-unsafe-eval' (and 'self') for scripts.","Confirm initWasmMcp() is only invoked when `browser` is true and after the component mounted.","Rebuild the WASM package; a stale glue file can export a different shape than loadWasm expects."],"exampleFix":"// before\nconst wasm = await loadWasm();\nif (!wasm) throw new Error(\"Failed to load WASM module\");\n// after\nconst wasm = await loadWasm();\nif (!wasm || typeof wasm.WasmMcpServer !== \"function\") {\n  throw new Error(`Failed to load WASM module (exports: ${Object.keys(wasm ?? {}).join(\",\")})`);\n}","handlingStrategy":"try-catch","validationCode":"function wasmLikelyAvailable(): boolean {\n  return (\n    typeof WebAssembly === \"object\" &&\n    typeof WebAssembly.instantiate === \"function\" &&\n    // CSP must allow wasm; not directly testable, but feature-detect compile\n    typeof WebAssembly.compile === \"function\"\n  );\n}\nif (browser && !wasmLikelyAvailable()) {\n  console.warn(\"WebAssembly unavailable; WASM MCP will be disabled\");\n}","typeGuard":"interface WasmExports {\n  WasmMcpServer: new () => unknown;\n  WasmGallery: new () => unknown;\n}\nfunction isWasmExports(w: unknown): w is WasmExports {\n  return (\n    !!w &&\n    typeof (w as WasmExports).WasmMcpServer === \"function\" &&\n    typeof (w as WasmExports).WasmGallery === \"function\"\n  );\n}","tryCatchPattern":"try {\n  const ok = await initWasmMcp();\n  if (!ok) wasmMcpState.update((s) => ({ ...s, error: \"WASM MCP unavailable\" }));\n} catch (e) {\n  wasmMcpState.update((s) => ({ ...s, loaded: false, loading: false, error: String((e as Error)?.message ?? e) }));\n}","preventionTips":["Ship the .wasm asset with the correct Content-Type (application/wasm) and a 200 in the build output.","Add 'wasm-unsafe-eval' to script-src in your CSP when WASM MCP is enabled.","Call initWasmMcp lazily (on first user action) so a failure does not break page load."],"tags":["wasm","browser","mcp","initialization"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}