{"record":{"id":"29c3cc3c39c51621","repo":"sveltejs/kit","slug":"could-not-get-the-request-store","errorCode":null,"errorMessage":"Could not get the request store.","messagePattern":"Could not get the request store\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/exports/internal/server/event.js","lineNumber":59,"sourceCode":"\t}\n\n\treturn event;\n}\n\nexport function get_request_store() {\n\tconst result = try_get_request_store();\n\tif (!result) {\n\t\tlet message = 'Could not get the request store.';\n\n\t\tif (als) {\n\t\t\tmessage += ' This is an internal error.';\n\t\t} else {\n\t\t\tmessage +=\n\t\t\t\t' In environments without `AsyncLocalStorage`, the request store (used by e.g. remote functions) must be accessed synchronously, not after an `await`.' +\n\t\t\t\t' If it was accessed synchronously then this is an internal error.';\n\t\t}\n\n\t\tthrow new Error(message);\n\t}\n\treturn result;\n}\n\nexport function try_get_request_store() {\n\treturn sync_store ?? als?.getStore() ?? null;\n}\n\n/**\n * @template T\n * @param {RequestStore | null} store\n * @param {() => T} fn\n */\nexport function with_request_store(store, fn) {\n\ttry {\n\t\tsync_store = store;\n\t\treturn als ? als.run(store, fn) : fn();\n\t} finally {","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/exports/internal/server/event.js#L41-L77","documentation":"`get_request_store()` fetches the per-request store (used by remote functions and related state) from `AsyncLocalStorage`. If no store exists in the current async context, it throws. Like `getRequestEvent`, it must be accessed synchronously within a request, and if accessed synchronously yet still missing, it indicates an internal error.","triggerScenarios":"Calling `get_request_store()` outside a server request, from detached async callbacks, or after `await` in environments lacking `AsyncLocalStorage` — commonly from remote function helpers or code reading `state`.","commonSituations":"Using remote-function internals in a plain script or test without a request wrapper; queueing work on `setImmediate` that reads the store; Cloudflare Workers without the ALS polyfill after an await boundary.","solutions":["Call `get_request_store()` synchronously at function start and hold the reference across awaits.","Ensure the call happens inside a server request context (remote functions, load, actions, hooks).","Use `try_get_request_store()` when a store may legitimately be absent, and handle `null`.","If it fails synchronously inside a valid request, file an issue — it may be an internal error from version mismatch; clear caches and align `@sveltejs/kit` and vite plugin versions."],"exampleFix":"// before\nasync function helper() {\n  await setup();\n  const { state } = get_request_store();\n}\n// after\nfunction helper() {\n  const store = get_request_store();\n  return async () => { await setup(); return store.state; };\n}","handlingStrategy":"fallback","validationCode":"import { try_get_request_store } from '@sveltejs/kit/internal';\nconst store = try_get_request_store();\nif (!store) {\n  // not in a request context — skip or use defaults\n}","typeGuard":null,"tryCatchPattern":"let store;\ntry {\n  store = get_request_store();\n} catch {\n  store = null; // degrade gracefully outside request scope\n}","preventionTips":["Prefer try_get_request_store() when the store is optional.","Read the store synchronously before awaits.","Only use remote-function internals within request-scoped code.","Keep @sveltejs/kit versions aligned across the monorepo to avoid internal mismatches."],"tags":["async-context","asynclocalstorage","request-store","remote-functions","sveltekit"],"backgroundTag":"missing-async-context","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}