{"record":{"id":"739210293cb77a89","repo":"sveltejs/kit","slug":"the-redirects-file-should-be-placed-in-the-projec","errorCode":null,"errorMessage":"The _redirects file should be placed in the project root rather than the ${builder.config.files.assets} directory","messagePattern":"The _redirects file should be placed in the project root rather than the (.+?) directory","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapter-cloudflare/index.js","lineNumber":45,"sourceCode":"\t\tname,\n\t\tasync adapt(builder) {\n\t\t\tif (\n\t\t\t\tfs.existsSync('_routes.json') ||\n\t\t\t\tfs.existsSync(`${builder.config.files.assets}/_routes.json`)\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Cloudflare Pages' _routes.json should be configured from the adapter option of the SvelteKit plugin in your vite.config.js. See https://svelte.dev/docs/kit/adapter-cloudflare#Options-routes\"\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (fs.existsSync(`${builder.config.files.assets}/_headers`)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`The _headers file should be placed in the project root rather than the ${builder.config.files.assets} directory`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (fs.existsSync(`${builder.config.files.assets}/_redirects`)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`The _redirects file should be placed in the project root rather than the ${builder.config.files.assets} directory`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst { wrangler_config, building_for_cloudflare_pages } = validate_wrangler_config(\n\t\t\t\toptions.config\n\t\t\t);\n\n\t\t\tlet dest = builder.getBuildDirectory('cloudflare');\n\t\t\tlet worker_dest = `${dest}/_worker.js`;\n\t\t\tlet assets_binding = 'ASSETS';\n\n\t\t\tif (building_for_cloudflare_pages) {\n\t\t\t\tif (wrangler_config.pages_build_output_dir) {\n\t\t\t\t\tdest = wrangler_config.pages_build_output_dir;\n\t\t\t\t\tworker_dest = `${dest}/_worker.js`;\n\t\t\t\t}\n\t\t\t} else {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/adapter-cloudflare/index.js#L27-L63","documentation":"Same guard as `_headers`, but for Cloudflare Pages' `_redirects` file. `_redirects` is only processed at the root of the deployment, so the adapter rejects a copy placed inside the generated assets directory (`builder.config.files.assets`). Throwing during `adapt` prevents shipping a redirects file that Cloudflare would silently ignore.","triggerScenarios":"Running `vite build` with the cloudflare adapter while `fs.existsSync(builder.config.files.assets + '/_redirects')` is true — i.e. a `_redirects` file sits directly in the adapter's assets output directory at adapt time.","commonSituations":"Migrating a plain Cloudflare Pages project where `_redirects` lived in the build output folder; a CI step copies `_redirects` into the output directory; users confuse the adapter's assets output dir with the source `static/` dir.","solutions":["Remove `_redirects` from the adapter's assets output directory (e.g. `.svelte-kit/cloudflare/_redirects`).","Put `_redirects` in the project root `static/` directory so it lands at the deployment root.","Re-run `vite build` and confirm the adapter completes without throwing."],"exampleFix":"// before: .svelte-kit/cloudflare/_redirects exists\n// rm .svelte-kit/cloudflare/_redirects\n// after\n// mv .svelte-kit/cloudflare/_redirects static/_redirects","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nif (fs.existsSync('.svelte-kit/cloudflare/_redirects')) {\n  throw new Error('Move _redirects to static/ so it lands at the deployment root');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep `_redirects` only in the `static/` directory","Do not copy files from legacy Pages setups into the adapter output directory","Verify after `vite build` that the file appears at the root of the deployed output"],"tags":["cloudflare-pages","adapter","build-time","config"],"backgroundTag":"cloudflare-pages-headers-redirects-misplaced","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}