{"record":{"id":"bc75e310c3f6a4ce","repo":"sveltejs/kit","slug":"read-failed-could-not-fetch-url-respon","errorCode":null,"errorMessage":"read(...) failed: could not fetch ${url} (${response.status} ${response.statusText})","messagePattern":"read\\(\\.\\.\\.\\) failed: could not fetch (.+?) \\((.+?) (.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapter-cloudflare/files/worker.js","lineNumber":25,"sourceCode":"\nconst immutable = `/${APP_PATH}/immutable/`;\nconst version_file = `/${APP_PATH}/version.json`;\n\n/**\n * We don't know the origin until we receive a request, but\n * that's guaranteed to happen before we call `read`\n * @type {string}\n */\nlet origin;\n\nconst initialized = server.init({\n\tenv,\n\tread: async (file) => {\n\t\tconst url = `${origin}/${file}`;\n\t\tconst response = await env.ASSETS_BINDING.fetch(url);\n\n\t\tif (!response.ok) {\n\t\t\tthrow new Error(\n\t\t\t\t`read(...) failed: could not fetch ${url} (${response.status} ${response.statusText})`\n\t\t\t);\n\t\t}\n\n\t\treturn response.body;\n\t}\n});\n\n/** @type {import('@cloudflare/workers-types').ExportedHandler<Cloudflare.Env>} */\nexport default {\n\tasync fetch(req, env) {\n\t\tif (!origin) {\n\t\t\torigin = new URL(req.url).origin;\n\t\t}\n\n\t\t// always await initialization to prevent race condition with concurrent requests\n\t\tawait initialized;\n","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/adapter-cloudflare/files/worker.js#L7-L43","documentation":"In the Cloudflare Workers adapter, the SvelteKit `read` function fetches static files from the ASSETS binding. If the response is not ok (404, 500, etc.), it throws with the URL and status so developers learn a requested file could not be served from assets rather than getting an opaque stream failure.","triggerScenarios":"Server code calls `read('some/file')` during SSR for a file that is not in the deployed static assets — wrong path, file excluded from build output, or ASSETS binding misconfigured in wrangler.toml.","commonSituations":"Reading files that were never added to the static directory; case-sensitivity mismatches (works on mac dev, fails on CF); files ignored by .assetsignore or not matching adapter copy rules.","solutions":["Verify the file exists in your static/ (or configured assets) directory and the path passed to read() matches exactly, including case.","Check wrangler.toml/wrangler.jsonc: the assets binding and directory must point at the built client assets.","Confirm the file is present in the deployed worker assets (cf. `wrangler deploy --dry-run` output or dashboard).","If the file may legitimately be missing, handle rejection or check availability instead of calling read()."],"exampleFix":"// before\nconst stream = read('static/logo.svg'); // wrong: path is relative to assets root\n// after\nconst stream = read('logo.svg');","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const stream = read('logo.svg');\n} catch (err) {\n  if (/could not fetch .* \\(404/.test(err.message)) {\n    console.error('Asset missing from deployment; check path/case and build output');\n  }\n  throw err;\n}","preventionTips":["Keep read() paths relative to the assets root and case-exact.","Verify the file lands in the deployed assets (check build output / wrangler dry-run).","Check the ASSETS_BINDING directory in wrangler config points at built client assets."],"tags":["cloudflare","assets","file-not-found","network"],"backgroundTag":"asset-fetch-failed","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}