dotnet/runtime · critical · Error

Failed to load WebAssembly module. HTTP status

Error message

Failed to load WebAssembly module. HTTP status: ${res?.status} ${res?.statusText}

What it means

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.

Solutions

  1. Confirm dotnet.wasm is deployed under _framework/ and reachable at the resolved URL with HTTP 200 and Content-Type application/wasm.
  2. Fix CORS headers and the application base so the response is usable (avoid opaque no-cors responses).
  3. If using a custom loadBootResourceCallback for the wasm, return a Response that resolves ok:true.
  4. Clear any stale service worker that may be serving a cached error page for dotnet.wasm.

Example fix

// before
loadBootResource: (t, n, uri) => fetch(uri, { mode: 'no-cors' }) // opaque -> res.ok === false

// after
loadBootResource: (t, n, uri) => fetch(uri) // proper CORS Response, ok:true
Defensive patterns

Strategy: retry

Validate before calling

async function probeWasm(url: string): Promise<boolean> {
  const r = await fetch(url, { method: 'HEAD' });
  return r.ok && (r.headers.get('Content-Type') || '').includes('application/wasm');
}

Try / catch

try {
  await instantiateWasm(wasmBinaryPromise, imports);
} catch (err) {
  if (/Failed to load WebAssembly module/.test(String((err as Error).message))) {
    // redeploy dotnet.wasm, fix CORS, or clear a stale service worker
  }
  throw err;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of dotnet/runtime@60108ba66e (2026-08-10). Data as JSON: /api/errors/e4371d07faaea4c5. Report an issue: GitHub.

Appendix: source

Thrown at src/native/libs/Common/JavaScript/host/assets.ts:248

            const data = await res.arrayBuffer();
            module = await WebAssembly.compile(data);
            instance = await WebAssembly.instantiate(module, imports);
        } else {
            const instantiated = await WebAssembly.instantiateStreaming(wasmPromise, imports);
            instance = instantiated.instance;
            module = instantiated.module;
        }
        return { instance, module };
    } catch (err) {
        _ems_.dotnetApi.exit(1, err);
        throw err;
    }

    async function checkResponseOk(wasmPromise: Promise<Response> | undefined): Promise<Response & { isStreamingOk?: boolean }> {
        _ems_.dotnetAssert.check(wasmPromise, "WASM binary promise was not initialized");
        const res = (await wasmPromise) as Response & { isStreamingOk?: boolean };
        if (!res || res.ok === false) {
            throw new Error(`Failed to load WebAssembly module. HTTP status: ${res?.status} ${res?.statusText}`);
        }
        res.isStreamingOk = typeof globalThis.Response === "function" && res instanceof globalThis.Response;
        const contentType = res.headers && res.headers.get ? res.headers.get("Content-Type") : undefined;
        if (_ems_.ENVIRONMENT_IS_WEB && contentType !== "application/wasm") {
            _ems_.dotnetLogger.warn("WebAssembly resource does not have the expected content type \"application/wasm\", so falling back to slower ArrayBuffer instantiation.");
            res.isStreamingOk = false;
        }
        return res;
    }
}

View on GitHub (pinned to 60108ba66e)