{"record":{"id":"16e779c4c0371ad2","repo":"sveltejs/kit","slug":"prerendered-error","errorCode":null,"errorMessage":"${prerendered.error}","messagePattern":"\\$\\{prerendered\\.error\\}","errorType":"http","errorClass":"HandledHttpError","httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/app/server/remote/prerender.js","lineNumber":116,"sourceCode":"\t\t\t\t/** @type {RemoteFunctionResponse | undefined} */\n\t\t\t\tlet prerendered;\n\n\t\t\t\ttry {\n\t\t\t\t\t// TODO adapters can provide prerendered data more efficiently than\n\t\t\t\t\t// fetching from the public internet\n\t\t\t\t\t// `request.url` rather than `event.url`, which throws inside queries\n\t\t\t\t\tconst response = await fetch(new URL(url, event.request.url).href);\n\n\t\t\t\t\tif (response.ok) {\n\t\t\t\t\t\tprerendered = /** @type {RemoteFunctionResponse} */ (await response.json());\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// not available prerendered, fallback to normal function\n\t\t\t\t}\n\n\t\t\t\tif (prerendered) {\n\t\t\t\t\tif (prerendered.type === 'error') {\n\t\t\t\t\t\tthrow new HandledHttpError(prerendered.error);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn parse(prerendered.data)._;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// during a prerender run, the same function might be invoked while rendering\n\t\t\t// multiple pages — share the result across the entire run\n\t\t\tif (state.prerendering?.remote_responses.has(url)) {\n\t\t\t\treturn /** @type {Promise<any>} */ (state.prerendering.remote_responses.get(url));\n\t\t\t}\n\n\t\t\tconst promise = run_remote_function(\n\t\t\t\tevent,\n\t\t\t\t{ ...state, is_in_remote_prerender: true },\n\t\t\t\tfalse,\n\t\t\t\t() => validate(arg),\n\t\t\t\tfn","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/app/server/remote/prerender.js#L98-L134","documentation":"During prerendering, remote functions first look up a prerendered response cache entry. If that entry is of type 'error', the stored error is re-thrown as a HandledHttpError with the prerendered error's original message, reproducing the failure that was captured when the page was prerendered.","triggerScenarios":"A remote function is invoked during runtime (or prerender fallback) and finds a prerendered cache entry whose type is 'error' — i.e. the remote call failed when the page was originally prerendered and that failure was serialized into the prerender manifest.","commonSituations":"Deploying prerendered pages whose remote query/command failed at build time (expired tokens, missing env vars at build); stale .svelte-kit output after an API change; a prerendered page snapshotting an intermittent backend failure.","solutions":["Fix the root error the remote function threw during prerendering (check build logs for the original failure)","Delete the .svelte-kit/build output and re-prerender so the error entry is regenerated","Guard the remote call with a fallback so it does not fail during prerender","Ensure required env vars/secrets are available at build time"],"exampleFix":"// before: prerendered page captured a failing query\nexport const load = async () => ({ posts: await getPosts() }); // fails at build if API down\n// after\nimport { prerender } from '$app/server';\nexport const load = async () => {\n  try {\n    return { posts: await getPosts() };\n  } catch {\n    return { posts: [] };\n  }\n};","handlingStrategy":"fallback","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  return await myQuery(arg);\n} catch (e) {\n  return fallbackValue; // don't let prerendered error entries propagate\n}","preventionTips":["Make remote functions prerender-safe with try/catch fallbacks","Always re-prerender after fixing build-time failures","Verify env vars exist at build time","Inspect the prerender manifest for error-type entries before deploy"],"tags":["prerendering","remote-functions","cache","ssr"],"backgroundTag":"prerendered-error-cache-hit","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}