{"record":{"id":"f3a4fe465c660e09","repo":"sveltejs/kit","slug":"the-redirects-file-should-be-placed-in-the-projec-f3a4fe","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":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapter-netlify/index.js","lineNumber":53,"sourceCode":"export default function ({ split = false, edge = edge_set_in_env_var } = {}) {\n\treturn {\n\t\tname,\n\t\tasync adapt(builder) {\n\t\t\tif (!builder.routes) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'@sveltejs/adapter-netlify >=2.x (possibly installed through @sveltejs/adapter-auto) requires @sveltejs/kit version 1.5 or higher. ' +\n\t\t\t\t\t\t'Either downgrade the adapter or upgrade @sveltejs/kit'\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (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 (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 netlify_config = get_netlify_config();\n\n\t\t\t// \"build\" is the default publish directory when Netlify detects SvelteKit\n\t\t\tconst publish = get_publish_directory(netlify_config, builder) || 'build';\n\n\t\t\t// empty out existing build directories\n\t\t\trmSync(publish, { force: true, recursive: true });\n\t\t\trmSync('.netlify/v1', { force: true, recursive: true });\n\n\t\t\t// clean up legacy directories from older adapter versions to avoid\n\t\t\t// gnarly edge cases when an existing project is upgraded to this version\n\t\t\trmSync('.netlify/edge-functions', { force: true, recursive: true });\n\t\t\trmSync('.netlify/server', { force: true, recursive: true });\n\t\t\trmSync('.netlify/package.json', { force: true, recursive: true });","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/adapter-netlify/index.js#L35-L71","documentation":"Netlify's _redirects file must be in the publish directory to take effect; SvelteKit's static assets directory is not the publish root (the adapter writes its own generated redirects there). Finding _redirects inside the static assets directory during adapt() triggers this error so redirects are never silently ignored.","triggerScenarios":"A file named _redirects exists in kit.files.assets (usually `static`) when the Netlify adapter runs adapt().","commonSituations":"Migrating from a non-SvelteKit Netlify setup that kept _redirects in the public folder; copying Netlify starter files into static/; following outdated tutorials.","solutions":["Move _redirects from the static directory to the project root","Express the redirects in SvelteKit's own routing (src/routes) where possible, or keep them in the root _redirects the adapter copies to publish","Delete static/_redirects if it duplicates rules handled by the adapter"],"exampleFix":"// shell\ngit mv static/_redirects ./_redirects","handlingStrategy":"validation","validationCode":"import { existsSync } from 'node:fs';\nif (existsSync('static/_redirects')) throw new Error('Move static/_redirects to the project root');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep _redirects in the project root, never in static/","Prefer SvelteKit route-level redirects over _redirects where possible","Add a prebuild script that fails fast if _redirects is in the wrong place"],"tags":["config","netlify","file-placement"],"backgroundTag":"file-in-wrong-directory","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}