{"record":{"id":"a09052b6d6eae38e","repo":"sveltejs/kit","slug":"name-cookie-does-not-exist-for-url-pathname","errorCode":null,"errorMessage":"'${name}' cookie does not exist for ${url.pathname}, but was previously set at ${conjoin([...paths])}. Did you mean to set its 'path' to '/' instead?","messagePattern":"'(.+?)' cookie does not exist for (.+?), but was previously set at (.+?)\\. Did you mean to set its 'path' to '/' instead\\?","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/kit/src/runtime/server/cookie.js","lineNumber":116,"sourceCode":"\t\t\t}\n\n\t\t\tif (best_match) {\n\t\t\t\treturn best_match.options.maxAge === 0 ? undefined : best_match.value;\n\t\t\t}\n\n\t\t\tconst cookie = parse_header(opts)[name]; // the decoded string or undefined\n\n\t\t\t// in development, if the cookie was set during this session with `cookies.set`,\n\t\t\t// but at a different path, warn the user. (ignore cookies from request headers,\n\t\t\t// since we don't know which path they were set at)\n\t\t\tif (DEV && !cookie) {\n\t\t\t\tconst paths = Array.from(cookie_paths[name] ?? []).filter((path) => {\n\t\t\t\t\t// we only care about paths that are _more_ specific than the current path\n\t\t\t\t\treturn path_matches(path, url.pathname) && path !== url.pathname;\n\t\t\t\t});\n\n\t\t\t\tif (paths.length > 0) {\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t// prettier-ignore\n\t\t\t\t\t\t`'${name}' cookie does not exist for ${url.pathname}, but was previously set at ${conjoin([...paths])}. Did you mean to set its 'path' to '/' instead?`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn cookie;\n\t\t},\n\n\t\tgetAll(opts) {\n\t\t\t// copy, so the cached parse isn't mutated below\n\t\t\tconst cookies = { ...parse_header(opts) };\n\n\t\t\t// Group cookies by name and find the most specific one for each name\n\t\t\tconst lookup = new Map();\n\n\t\t\tfor (const c of new_cookies.values()) {\n\t\t\t\tif (matches_url(c)) {","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/server/cookie.js#L98-L134","documentation":"When reading a cookie via `cookies.get(name)` at a URL path where it does not exist, but the cookie was previously set during the same request at a more specific path, SvelteKit warns. Cookies are path-scoped, so a cookie set with `path: '/admin'` is invisible to `get()` calls at other paths. The warning suggests you probably wanted the cookie visible everywhere and should set `path: '/'`.","triggerScenarios":"In one request: `cookies.set('session', value, { path: '/settings' })` then later `cookies.get('session')` at a URL like `/` or another pathname — `get` finds no cookie for the current path but the set-cookie path matches more specifically, triggering the warn.","commonSituations":"Setting a login or preference cookie inside a nested route action/hook without specifying `path`, then reading it elsewhere on the site during the same or subsequent request handling.","solutions":["Set the cookie with `path: '/'` so it is readable at every URL path.","Read the cookie from the same path scope where it was set, or explicitly pass the matching path semantics in your own logic.","If the path scoping is intentional, ignore/restructure the code so `get` is only called within the scoped path."],"exampleFix":"// before\ncookies.set('session', token, { path: '/account' });\n// after\ncookies.set('session', token, { path: '/' });","handlingStrategy":"validation","validationCode":"// always validate the path option when setting cookies\nfunction setSessionCookie(cookies, name, value) {\n  if (!options.path || options.path !== '/') {\n    console.warn(`cookie ${name} set with path ${options.path}; will not be readable site-wide`);\n  }\n  cookies.set(name, value, { path: '/', ...options });\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default every `cookies.set` call to `path: '/'` unless path scoping is deliberate.","Centralize cookie set/get in one helper module so path options are consistent.","Test cookie reads from a different route than the one that sets them."],"tags":["cookies","server","sveltekit"],"backgroundTag":"cookie-path-scope-mismatch","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}