{"record":{"id":"92d0c1cd2d27b6ef","repo":"schollz/croc","slug":"could-not-load-croc-wasm-response-status","errorCode":null,"errorMessage":"Could not load croc.wasm (${response.status})","messagePattern":"Could not load croc\\.wasm \\((.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"web/public/croc-worker.js","lineNumber":12,"sourceCode":"/* global Go, crocWasm */\n\nlet ready;\n\nfunction initialize() {\n  if (ready) return ready;\n  ready = (async () => {\n    importScripts(new URL(\"./wasm_exec.js\", self.location.href).href);\n    const go = new Go();\n    const response = await fetch(new URL(\"./croc.wasm\", self.location.href));\n    if (!response.ok) {\n      throw new Error(`Could not load croc.wasm (${response.status})`);\n    }\n    const bytes = await response.arrayBuffer();\n    const { instance } = await WebAssembly.instantiate(bytes, go.importObject);\n    void go.run(instance);\n    for (let attempts = 0; !self.crocWasm && attempts < 100; attempts += 1) {\n      await new Promise((resolve) => setTimeout(resolve, 10));\n    }\n    if (!self.crocWasm) {\n      throw new Error(\"croc WASM did not initialize\");\n    }\n  })();\n  return ready;\n}\n\nfunction transferables(value, output = []) {\n  if (value instanceof Uint8Array) {\n    output.push(value.buffer);\n  } else if (value && typeof value === \"object\") {","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/schollz/croc/blob/e25f1bdc04f07f094d50b0a1bf67e2563944b57a/web/public/croc-worker.js#L1-L30","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the interpolated HTTP status: 404/410 means the asset is absent, 5xx means the server/gateway failed","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)","Open the wasm URL directly in a browser to see what the server returns and fix the static file mapping or CDN rule","If behind a reverse proxy, add an exception so /croc.wasm is served as a static binary with correct MIME type"],"exampleFix":"// before: croc.wasm missing from dist/\n// dist/croc-worker.js exists, dist/croc.wasm missing -> fetch returns 404\n\n// after: copy the wasm artifact into the public output in the build step\n// package.json / build script:\n//   \"build\": \"vite build && cp build/croc.wasm dist/croc.wasm\"","handlingStrategy":"retry","validationCode":"// Before spinning up the worker, verify the wasm asset is reachable\nasync function wasmAssetOk() {\n  const res = await fetch(new URL(\"./croc.wasm\", location.href), { method: \"HEAD\" });\n  return res.ok;\n}\nif (!(await wasmAssetOk())) throw new Error(\"croc.wasm is not deployed next to the app\");","typeGuard":null,"tryCatchPattern":"// In the worker RPC wrapper: retry transient 5xx once, surface 404 as fatal\ntry {\n  await initialize();\n} catch (e) {\n  if (/\\(5\\d\\d\\)$/.test(e.message) && !retried) { ready = undefined; return initialize(); }\n  throw e;\n}","preventionTips":["Add a build check that fails CI if croc.wasm is missing from the deploy output","Serve wasm with correct MIME type (application/wasm) and no rewrite rules on that path","Keep croc-worker.js, wasm_exec.js, and croc.wasm in the same directory so relative URLs resolve"],"tags":["wasm","deployment","http","web-worker"],"backgroundTag":null,"analyzedSha":"e25f1bdc04f07f094d50b0a1bf67e2563944b57a","analyzedAt":"2026-08-15T12:53:39.096Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}