schollz/croc · error · Error

Could not load croc.wasm (${response.status})

Error message

Could not load croc.wasm (${response.status})

What it means

Thrown inside the Web Worker when the HTTP fetch of croc.wasm (resolved relative to the worker script URL) returns a non-OK status. The status code is interpolated into the message, so 404 means the file is missing from the deployed web/public directory and 500/502 usually means the static server or gateway failed. The worker resolves the wasm path with new URL("./croc.wasm", self.location.href), so it is fetched from the same directory the worker itself was loaded from.

Source

Thrown at web/public/croc-worker.js:12

/* global Go, crocWasm */

let ready;

function initialize() {
  if (ready) return ready;
  ready = (async () => {
    importScripts(new URL("./wasm_exec.js", self.location.href).href);
    const go = new Go();
    const response = await fetch(new URL("./croc.wasm", self.location.href));
    if (!response.ok) {
      throw new Error(`Could not load croc.wasm (${response.status})`);
    }
    const bytes = await response.arrayBuffer();
    const { instance } = await WebAssembly.instantiate(bytes, go.importObject);
    void go.run(instance);
    for (let attempts = 0; !self.crocWasm && attempts < 100; attempts += 1) {
      await new Promise((resolve) => setTimeout(resolve, 10));
    }
    if (!self.crocWasm) {
      throw new Error("croc WASM did not initialize");
    }
  })();
  return ready;
}

function transferables(value, output = []) {
  if (value instanceof Uint8Array) {
    output.push(value.buffer);
  } else if (value && typeof value === "object") {

View on GitHub (pinned to e25f1bdc04)

Solutions

  1. Check the interpolated HTTP status: 404/410 means the asset is absent, 5xx means the server/gateway failed
  2. Verify croc.wasm actually exists in the deployed directory next to croc-worker.js and wasm_exec.js (it is fetched relative to the worker URL)
  3. Open the wasm URL directly in a browser to see what the server returns and fix the static file mapping or CDN rule
  4. If behind a reverse proxy, add an exception so /croc.wasm is served as a static binary with correct MIME type

Example fix

// before: croc.wasm missing from dist/
// dist/croc-worker.js exists, dist/croc.wasm missing -> fetch returns 404

// after: copy the wasm artifact into the public output in the build step
// package.json / build script:
//   "build": "vite build && cp build/croc.wasm dist/croc.wasm"
Defensive patterns

Strategy: retry

Validate before calling

// Before spinning up the worker, verify the wasm asset is reachable
async function wasmAssetOk() {
  const res = await fetch(new URL("./croc.wasm", location.href), { method: "HEAD" });
  return res.ok;
}
if (!(await wasmAssetOk())) throw new Error("croc.wasm is not deployed next to the app");

Try / catch

// In the worker RPC wrapper: retry transient 5xx once, surface 404 as fatal
try {
  await initialize();
} catch (e) {
  if (/\(5\d\d\)$/.test(e.message) && !retried) { ready = undefined; return initialize(); }
  throw e;
}

Prevention

When it happens

Trigger: Deploying the web build without copying croc.wasm into the public output directory; a CDN/gateway rewrite that strips or blocks .wasm files; the worker being loaded cross-origin so the relative URL points at the wrong host; a dev server proxy returning 404/502 for the wasm asset.

Common situations: CI build pipelines that prune large binary assets; misconfigured SPA rewrites that route unknown extensions to index.html (status 200 but wrong content) or reject them; staging servers missing the artifact produced by the Go wasm build step.

Related errors


AI-assisted analysis of schollz/croc@e25f1bdc04 (2026-08-15). Data as JSON: /api/errors/92d0c1cd2d27b6ef. Report an issue: GitHub.