{"record":{"id":"bab602c942b311ee","repo":"sveltejs/kit","slug":"the-headers-file-should-be-placed-in-the-project-bab602","errorCode":null,"errorMessage":"The _headers file should be placed in the project root rather than the ${builder.config.files.assets} directory","messagePattern":"The _headers 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":47,"sourceCode":"const netlify_framework_serverless_path = '.netlify/v1/functions';\nconst netlify_framework_edge_path = '.netlify/v1/edge-functions';\n\nconst FUNCTION_PREFIX = 'sveltekit-';\n\n/** @type {typeof import('./index.js').default} */\nexport 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 });","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/adapter-netlify/index.js#L29-L65","documentation":"Netlify reads custom HTTP headers from a _headers file that must live in the publish (site root) directory. SvelteKit's static assets directory is where your own assets live, but the adapter generates/copies _headers itself; a user-supplied _headers inside the static directory would conflict or be ignored, so the adapter throws during adapt().","triggerScenarios":"A file named _headers exists in the directory configured as kit.files.assets (usually `static`), detected by existsSync during adapt().","commonSituations":"Following generic Netlify docs that say to put _headers in the repo root or public folder, while SvelteKit's equivalent static folder is not the publish root; migrating a plain Netlify static site to SvelteKit keeping old _headers in static/.","solutions":["Move _headers from the static directory to the project root","Merge any custom header rules into the project-root _headers file the adapter will copy to publish","Delete the file from static/ if the rules are already handled elsewhere"],"exampleFix":"// shell\ngit mv static/_headers ./_headers","handlingStrategy":"validation","validationCode":"import { existsSync } from 'node:fs';\nif (existsSync('static/_headers')) throw new Error('Move static/_headers to the project root');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep _headers in the project root, never in static/","Add a CI check that fails if _headers exists inside the assets directory","Remember SvelteKit's static/ is not Netlify's publish root; the adapter copies root _headers for you"],"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"}