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 Netlify Edge Functions, the SvelteKit server's read() function (used by e.g. imports of files at runtime via the $app/server read API) fetches static assets from the origin over HTTP instead of reading from disk (Deno edge runtime has no filesystem access). If the fetch to `${origin}/${file}` returns a non-OK response, this error is thrown with the URL and HTTP status.
Source
Thrown at packages/adapter-netlify/files/edge.js:17
import { server } from '0SERVER';
/**
* 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: Deno.env.toObject(),
read: async (file) => {
const url = `${origin}/${file}`;
const response = await fetch(url);
if (!response.ok) {
throw new Error(
`read(...) failed: could not fetch ${url} (${response.status} ${response.statusText})`
);
}
return response.body;
}
});
/** @type {import('@netlify/edge-functions').EdgeFunction} */
export default async function handler(request, context) {
if (!origin) {
origin = new URL(request.url).origin;
}
// always await initialization to prevent race condition with concurrent requests
await initialized;
return server.respond(request, {View on GitHub (pinned to 03f1687fe6)
Solutions
- Verify the file exists in the site's published static/publish directory before calling read()
- Fix the path passed to read() — it must match the deployed asset path exactly (no leading slash issues)
- If the file is generated at runtime, store it in Netlify Blobs or an external store instead of relying on read()
- Wrap the call in try/catch and handle non-200 responses gracefully
Example fix
// before
const file = await read(`${params.slug}.json`);
// after
let file;
try {
file = await read(`${params.slug}.json`);
} catch (e) {
throw error(404, 'Asset not found');
} Defensive patterns
Strategy: try-catch
Validate before calling
const res = await fetch(`${origin}/${file}`, { method: 'HEAD' });
if (!res.ok) console.warn(`Asset ${file} not deployed (HTTP ${res.status})`); Try / catch
try {
const stream = await read(filePath);
} catch (err) {
if (err.message.startsWith('read(...) failed')) {
throw error(404, `Asset not available: ${filePath}`);
}
throw err;
} Prevention
- Ensure every file passed to read() exists in the published static assets
- Never call read() for runtime-generated files — use Netlify Blobs or KV instead
- Log the failing URL/status from the error to distinguish 404 (missing asset) from 5xx (origin issue)
When it happens
Trigger: Calling read('path') from an edge function for a file that does not exist in the published static assets (404), or the origin returning 403/500; requesting a path outside the deployed static directory.
Common situations: Edge function reading a user-uploaded or generated file that was never deployed; typo in the file path; file present locally but excluded from the build output; Netlify origin briefly erroring (5xx).
Related errors
- read(...) failed: could not fetch ${url} (${response.status}
- @sveltejs/adapter-netlify >=2.x (possibly installed through
- The _headers file should be placed in the project root rathe
- The _redirects file should be placed in the project root rat
- Cannot use `split: true` alongside `edge: true`
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/d82c1ec328683820.
Report an issue: GitHub.