sveltejs/kit · error
Cookie "${name}" is too large, and will be discarded by the
Error message
Cookie "${name}" is too large, and will be discarded by the browser What it means
Dev-only size check in the internal cookie setter: the encoded name+value pair exceeds SvelteKit's MAX_COOKIE_SIZE (4096 bytes, the browser cookie limit). In development SvelteKit throws so the problem is caught early; in production browsers would silently drop the cookie, losing session data.
Source
Thrown at packages/kit/src/runtime/server/cookie.js:253
let path = options.path ?? '/';
if (!options.domain || options.domain === url.hostname) {
path = resolve(normalized_url, path);
}
// Generate unique key for cookie storage
const cookie_key = generate_cookie_key(options.domain, path, name);
const cookie = { name, value, options: { ...options, path } };
new_cookies.set(cookie_key, cookie);
if (DEV) {
const size =
// only the name/value pair counts towards MAX_COOKIE_SIZE, not the other attributes
text_encoder.encode(name).byteLength +
text_encoder.encode((options.encode ?? encodeURIComponent)(value)).byteLength;
if (size > MAX_COOKIE_SIZE) {
throw new Error(`Cookie "${name}" is too large, and will be discarded by the browser`);
}
cookie_paths[name] ??= new Set();
if (!value) {
cookie_paths[name].delete(path);
} else {
cookie_paths[name].add(path);
}
}
}
/**
* @param {import('types').TrailingSlash} trailing_slash
*/
function set_trailing_slash(trailing_slash) {
normalized_url = normalize_path(url.pathname, trailing_slash);
internal_queue.forEach((fn) => fn());View on GitHub (pinned to 03f1687fe6)
Solutions
- Store large data server-side (e.g. in a database or session store) and keep only a session id in the cookie
- Shorten the cookie value or use a less verbose encoding
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at packages/kit/src/runtime/server/cookie.js:253 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/009ecf0facf39514.
Report an issue: GitHub.