sveltejs/kit · error · Error

read(...) failed: could not fetch ${url} (${response.status}

Error message

read(...) failed: could not fetch ${url} (${response.status} ${response.statusText})

What it means

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.

Source

Thrown at packages/adapter-cloudflare/files/worker.js:25

const immutable = `/${APP_PATH}/immutable/`;
const version_file = `/${APP_PATH}/version.json`;

/**
 * We don't know the origin until we receive a request, but
 * that's guaranteed to happen before we call `read`
 * @type {string}
 */
let origin;

const initialized = server.init({
	env,
	read: async (file) => {
		const url = `${origin}/${file}`;
		const response = await env.ASSETS_BINDING.fetch(url);

		if (!response.ok) {
			throw new Error(
				`read(...) failed: could not fetch ${url} (${response.status} ${response.statusText})`
			);
		}

		return response.body;
	}
});

/** @type {import('@cloudflare/workers-types').ExportedHandler<Cloudflare.Env>} */
export default {
	async fetch(req, env) {
		if (!origin) {
			origin = new URL(req.url).origin;
		}

		// always await initialization to prevent race condition with concurrent requests
		await initialized;

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Verify the file exists in your static/ (or configured assets) directory and the path passed to read() matches exactly, including case.
  2. Check wrangler.toml/wrangler.jsonc: the assets binding and directory must point at the built client assets.
  3. Confirm the file is present in the deployed worker assets (cf. `wrangler deploy --dry-run` output or dashboard).
  4. If the file may legitimately be missing, handle rejection or check availability instead of calling read().

Example fix

// before
const stream = read('static/logo.svg'); // wrong: path is relative to assets root
// after
const stream = read('logo.svg');
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const stream = read('logo.svg');
} catch (err) {
  if (/could not fetch .* \(404/.test(err.message)) {
    console.error('Asset missing from deployment; check path/case and build output');
  }
  throw err;
}

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/bc75e310c3f6a4ce. Report an issue: GitHub.