{"record":{"id":"a966e654a464a32d","repo":"sveltejs/kit","slug":"cannot-save-decoded-as-parent-is-already-a-f","errorCode":null,"errorMessage":"Cannot save ${decoded} as ${parent} is already a file. See https://svelte.dev/docs/kit/page-options#prerender-route-conflicts for more information","messagePattern":"Cannot save (.+?) as (.+?) is already a file\\. See https://svelte\\.dev/docs/kit/page-options#prerender-route-conflicts for more information","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/core/postbuild/prerender.js","lineNumber":603,"sourceCode":"\t\t\t} else {\n\t\t\t\tlog.warn(`location header missing on redirect received from ${decoded}`);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tif (response.status === 200) {\n\t\t\tif (existsSync(dest) && statSync(dest).isDirectory()) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot save ${decoded} as it is already a directory. See https://svelte.dev/docs/kit/page-options#prerender-route-conflicts for more information`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst dir = dirname(dest);\n\n\t\t\tif (existsSync(dir) && !statSync(dir).isDirectory()) {\n\t\t\t\tconst parent = decoded.split('/').slice(0, -1).join('/');\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot save ${decoded} as ${parent} is already a file. See https://svelte.dev/docs/kit/page-options#prerender-route-conflicts for more information`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tmkdirSync(dir, { recursive: true });\n\n\t\t\twriteFileSync(dest, body);\n\t\t\twritten.add(file);\n\n\t\t\tif (is_html) {\n\t\t\t\tprerendered.pages.set(decoded, {\n\t\t\t\t\tfile\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tprerendered.assets.set(decoded, {\n\t\t\t\t\ttype\n\t\t\t\t});\n\t\t\t}","sourceCodeStart":585,"sourceCodeEnd":621,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/core/postbuild/prerender.js#L585-L621","documentation":"A prerendered route's output destination's parent directory already exists as a FILE. This happens when one route (e.g. `/foo`) saved a file named `foo` (or `foo.html`) and another route (e.g. `/foo/bar`) needs `foo` to be a directory. Both cannot coexist on disk.","triggerScenarios":"Routes `/foo` (saving file `foo.html`/`foo`) and `/foo/bar` prerendered in the same build; typically caused by a dynamic segment colliding with a sibling file-producing route.","commonSituations":"A `[slug]` route generating slug \"bar\" under `/foo` while a static file-producing route `/foo` exists; endpoints returning files (e.g. `/docs` returning a PDF) alongside nested pages `/docs/intro`.","solutions":["Rename one of the conflicting routes so the file path and directory path differ","Nest the file-producing route, e.g. move the file endpoint from `/foo` to `/foo/index` or `/files/foo`","Adjust the dynamic route's generated slugs (exclude the colliding value) or use route groups to restructure paths","See https://svelte.dev/docs/kit/page-options#prerender-route-conflicts"],"exampleFix":"// before\n// src/routes/docs/+server.js   -> writes file 'docs'\n// src/routes/docs/intro/+page.svelte -> needs directory 'docs/'\n\n// after\n// src/routes/files/[name]/+server.js  -> /files/docs serves the file\n// src/routes/docs/intro/+page.svelte  -> docs/ stays a directory","handlingStrategy":"validation","validationCode":"// ensure no route is both a file producer and a path prefix of another\nconst routes = ['/docs', '/docs/intro'];\nfor (const r of routes) {\n  if (routes.some((o) => o !== r && o.startsWith(r + '/'))) {\n    console.warn(`Route ${r} is a prefix of another; file/dir clash possible in prerender`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await prerender();\n} catch (e) {\n  if (String(e.message).includes('is already a file')) {\n    console.error('A route output file collides with a nested route directory; rename one');\n  }\n  throw e;\n}","preventionTips":["Avoid routes that both return files and have child pages","Put downloadable files under a dedicated prefix like /files/","Constrain dynamic slugs to exclude values that collide with static siblings"],"tags":["prerender","route-conflict","filesystem"],"backgroundTag":"prerender-route-conflict","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}