{"record":{"id":"72e36f14bfdf4afd","repo":"withastro/astro","slug":"sessionstorageiniterror","errorCode":"SessionStorageInitError","errorMessage":"No driver was defined in the session configuration and the adapter did not provide a default driver.","messagePattern":"No driver was defined in the session configuration and the adapter did not provide a default driver\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/core/session/runtime.ts","lineNumber":89,"sourceCode":"\t// When we load the data from storage, we need to merge it with the local partial data,\n\t// preserving in-memory changes and deletions.\n\t#partial = true;\n\t#logger: AstroLogger;\n\t#driverFactory: SessionDriverFactory | null;\n\n\tstatic #sharedStorage = new Map<string, Storage>();\n\n\tconstructor({\n\t\tcookies,\n\t\tconfig,\n\t\truntimeMode,\n\t\tdriverFactory,\n\t\tmockStorage,\n\t\tlogger,\n\t}: AstroSessionOptions) {\n\t\tthis.#logger = logger;\n\t\tif (!config) {\n\t\t\tthrow new AstroError({\n\t\t\t\t...SessionStorageInitError,\n\t\t\t\tmessage: SessionStorageInitError.message(\n\t\t\t\t\t'No driver was defined in the session configuration and the adapter did not provide a default driver.',\n\t\t\t\t),\n\t\t\t});\n\t\t}\n\t\tthis.#cookies = cookies;\n\t\tthis.#driverFactory = driverFactory;\n\t\tconst { cookie: cookieConfig = DEFAULT_COOKIE_NAME, ...configRest } = config;\n\t\tlet cookieConfigObject: AstroCookieSetOptions | undefined;\n\t\tif (typeof cookieConfig === 'object') {\n\t\t\tconst { name = DEFAULT_COOKIE_NAME, ...rest } = cookieConfig;\n\t\t\tthis.#cookieName = name;\n\t\t\tcookieConfigObject = rest;\n\t\t} else {\n\t\t\tthis.#cookieName = cookieConfig || DEFAULT_COOKIE_NAME;\n\t\t}\n\t\tthis.#cookieConfig = {","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/core/session/runtime.ts#L71-L107","documentation":"Sessions require a configured storage driver. The AstroSession constructor throws AstroError code SessionStorageInitError when no session config was passed — i.e. there is no `session` block in astro.config.mjs and the active adapter did not provide a default driver, yet the sessions API was invoked.","triggerScenarios":"Calling Astro.session.set/get on a project with no `session` configuration and an adapter that supplies no default driver (or with no adapter at all).","commonSituations":"Enabling sessions in page/middleware code before adding the session config; using an adapter without built-in session driver support; mis-naming the session key in config.","solutions":["Add a session block to astro.config: `session: { driver: 'fs' }` (or another unstorage driver).","Use an adapter that provides a default session driver.","Verify the config file being loaded is the one you edited (check for multiple configs)."],"exampleFix":"// astro.config.mjs before\nexport default defineConfig({ adapter: node() });\n// after\nexport default defineConfig({ adapter: node(), session: { driver: 'fs' } });","handlingStrategy":"validation","validationCode":"import config from './astro.config.mjs';\nif (!config.session || config.session === false || !config.session.driver) {\n  throw new Error('Configure session.driver before using Astro.session (or use an adapter that provides a default driver).');\n}","typeGuard":"const hasSessionDriver = (cfg: any): boolean =>\n  !!cfg.session && cfg.session !== false && !!cfg.session.driver;","tryCatchPattern":null,"preventionTips":["Add a `session: { driver: '...' }` block before calling Astro.session.","Confirm your adapter provides a default session driver if you rely on that.","Gate session usage behind a config check in a setup script."],"tags":["session","config","ssr"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}