{"record":{"id":"e8e04602724276d9","repo":"sveltejs/kit","slug":"location-header-missing-on-redirect-received-from","errorCode":null,"errorMessage":"location header missing on redirect received from ${decoded}","messagePattern":"location header missing on redirect received from (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/kit/src/core/postbuild/prerender.js","lineNumber":586,"sourceCode":"\t\t\t\t\t\t)};</script><meta http-equiv=\"refresh\" content=\"${escape_html(\n\t\t\t\t\t\t\t`0;url=${location}`,\n\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t)}\">`\n\t\t\t\t\t);\n\n\t\t\t\t\twritten.add(file);\n\n\t\t\t\t\tif (!prerendered.redirects.has(decoded)) {\n\t\t\t\t\t\tprerendered.redirects.set(decoded, {\n\t\t\t\t\t\t\tstatus: response.status,\n\t\t\t\t\t\t\tlocation: resolved\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tprerendered.paths.push(decoded);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tlog.warn(`location header missing on redirect received from ${decoded}`);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tif (response.status === 200) {\n\t\t\tif (existsSync(dest) && statSync(dest).isDirectory()) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot save ${decoded} as it is already a directory. See https://svelte.dev/docs/kit/page-options#prerender-route-conflicts for more information`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst dir = dirname(dest);\n\n\t\t\tif (existsSync(dir) && !statSync(dir).isDirectory()) {\n\t\t\t\tconst parent = decoded.split('/').slice(0, -1).join('/');\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot save ${decoded} as ${parent} is already a file. See https://svelte.dev/docs/kit/page-options#prerender-route-conflicts for more information`","sourceCodeStart":568,"sourceCodeEnd":604,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/core/postbuild/prerender.js#L568-L604","documentation":"During prerendering, when a response with a redirect status (3xx) is received but no `location` header is present, prerender.js logs this warning and skips saving the redirect. SvelteKit cannot record a redirect without a target URL.","triggerScenarios":"A prerendered page (or endpoint) returns status 301/302/307/308 from `+server.js` or a `load` redirect without setting the `location` header, e.g. `redirect(302)` misuse or a hand-built `Response` with `status: 302` but no `Location` header.","commonSituations":"Manually constructing `new Response(null, { status: 302 })` in a prerendered endpoint; server-side redirects computed from missing env data; proxy responses stripped of headers.","solutions":["Use `redirect(status, location)` from `$app/navigation`/`@sveltejs/kit` in `+server.js` and load functions so the Location header is set","If building a raw Response, include `headers: { location: '/target' }`","Ensure any conditional redirect logic always has a non-empty target URL"],"exampleFix":"// before\nreturn new Response(null, { status: 302 });\n// after\nimport { redirect } from '@sveltejs/kit';\nreturn redirect(302, '/login'); // or new Response(null, { status: 302, headers: { location: '/login' } })","handlingStrategy":"validation","validationCode":"// endpoint guard before returning a manual redirect response\nif (res.status >= 300 && res.status < 400 && !res.headers.get('location')) {\n  throw new Error('redirect response missing location header');\n}","typeGuard":"/** @returns {res is Response & { headers: Headers & { get(k: 'location'): string } }} */\nfunction hasLocation(res) { return res.status >= 300 && res.status < 400 && !!res.headers.get('location'); }","tryCatchPattern":null,"preventionTips":["Always use the `redirect()` helper instead of hand-built Responses","Prerender locally and read prerender log warnings before deploying","Add a unit test asserting every 3xx endpoint response has a Location header"],"tags":["prerender","redirect","http-headers"],"backgroundTag":"missing-redirect-location-header","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}