{"record":{"id":"e4371d07faaea4c5","repo":"dotnet/runtime","slug":"failed-to-load-webassembly-module-http-status","errorCode":null,"errorMessage":"Failed to load WebAssembly module. HTTP status: ${res?.status} ${res?.statusText}","messagePattern":"Failed to load WebAssembly module\\. HTTP status: (.+?) (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"src/native/libs/Common/JavaScript/host/assets.ts","lineNumber":248,"sourceCode":"            const data = await res.arrayBuffer();\n            module = await WebAssembly.compile(data);\n            instance = await WebAssembly.instantiate(module, imports);\n        } else {\n            const instantiated = await WebAssembly.instantiateStreaming(wasmPromise, imports);\n            instance = instantiated.instance;\n            module = instantiated.module;\n        }\n        return { instance, module };\n    } catch (err) {\n        _ems_.dotnetApi.exit(1, err);\n        throw err;\n    }\n\n    async function checkResponseOk(wasmPromise: Promise<Response> | undefined): Promise<Response & { isStreamingOk?: boolean }> {\n        _ems_.dotnetAssert.check(wasmPromise, \"WASM binary promise was not initialized\");\n        const res = (await wasmPromise) as Response & { isStreamingOk?: boolean };\n        if (!res || res.ok === false) {\n            throw new Error(`Failed to load WebAssembly module. HTTP status: ${res?.status} ${res?.statusText}`);\n        }\n        res.isStreamingOk = typeof globalThis.Response === \"function\" && res instanceof globalThis.Response;\n        const contentType = res.headers && res.headers.get ? res.headers.get(\"Content-Type\") : undefined;\n        if (_ems_.ENVIRONMENT_IS_WEB && contentType !== \"application/wasm\") {\n            _ems_.dotnetLogger.warn(\"WebAssembly resource does not have the expected content type \\\"application/wasm\\\", so falling back to slower ArrayBuffer instantiation.\");\n            res.isStreamingOk = false;\n        }\n        return res;\n    }\n}\n","sourceCodeStart":230,"sourceCodeEnd":259,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/native/libs/Common/JavaScript/host/assets.ts#L230-L259","documentation":"Thrown by checkResponseOk() inside instantiateWasm() (src/native/libs/Common/JavaScript/host/assets.ts:244) when the Response for the main runtime wasm (dotnet.wasm) is falsy or res.ok === false. instantiateWasm awaits this before streaming/arrayBuffer instantiation, so a failed download of the core wasm binary surfaces as a clear HTTP error rather than a raw WebAssembly compile failure.","triggerScenarios":"fetchMainWasm() resolves wasmBinaryPromise via loadResource; instantiateWasm awaits checkResponseOk(wasmPromise). A 404 for dotnet.wasm, a 5xx, a CORS-blocked response, or an opaque no-cors Response triggers the throw; the catch then calls dotnetApi.exit(1, err).","commonSituations":"dotnet.wasm not deployed (404); wrong content path/CDN; CORS misconfiguration; integrity mismatch surfaced as a non-OK response; a service worker returning an error page; the wrong MIME type forcing the streaming path to fail.","solutions":["Confirm dotnet.wasm is deployed under _framework/ and reachable at the resolved URL with HTTP 200 and Content-Type application/wasm.","Fix CORS headers and the application base so the response is usable (avoid opaque no-cors responses).","If using a custom loadBootResourceCallback for the wasm, return a Response that resolves ok:true.","Clear any stale service worker that may be serving a cached error page for dotnet.wasm."],"exampleFix":"// before\nloadBootResource: (t, n, uri) => fetch(uri, { mode: 'no-cors' }) // opaque -> res.ok === false\n\n// after\nloadBootResource: (t, n, uri) => fetch(uri) // proper CORS Response, ok:true","handlingStrategy":"retry","validationCode":"async function probeWasm(url: string): Promise<boolean> {\n  const r = await fetch(url, { method: 'HEAD' });\n  return r.ok && (r.headers.get('Content-Type') || '').includes('application/wasm');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await instantiateWasm(wasmBinaryPromise, imports);\n} catch (err) {\n  if (/Failed to load WebAssembly module/.test(String((err as Error).message))) {\n    // redeploy dotnet.wasm, fix CORS, or clear a stale service worker\n  }\n  throw err;\n}","preventionTips":["Deploy dotnet.wasm with Content-Type application/wasm and correct CORS.","Return a usable (non-opaque) Response from any custom loadBootResourceCallback.","Bust stale service-worker caches when redeploying."],"tags":["network","wasm","http","deployment"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}