sveltejs/kit · error · Error
The _redirects file should be placed in the project root rat
Error message
The _redirects file should be placed in the project root rather than the ${builder.config.files.assets} directory What it means
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.
Source
Thrown at packages/adapter-cloudflare/index.js:45
name,
async adapt(builder) {
if (
fs.existsSync('_routes.json') ||
fs.existsSync(`${builder.config.files.assets}/_routes.json`)
) {
throw new Error(
"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"
);
}
if (fs.existsSync(`${builder.config.files.assets}/_headers`)) {
throw new Error(
`The _headers file should be placed in the project root rather than the ${builder.config.files.assets} directory`
);
}
if (fs.existsSync(`${builder.config.files.assets}/_redirects`)) {
throw new Error(
`The _redirects file should be placed in the project root rather than the ${builder.config.files.assets} directory`
);
}
const { wrangler_config, building_for_cloudflare_pages } = validate_wrangler_config(
options.config
);
let dest = builder.getBuildDirectory('cloudflare');
let worker_dest = `${dest}/_worker.js`;
let assets_binding = 'ASSETS';
if (building_for_cloudflare_pages) {
if (wrangler_config.pages_build_output_dir) {
dest = wrangler_config.pages_build_output_dir;
worker_dest = `${dest}/_worker.js`;
}
} else {View on GitHub (pinned to 03f1687fe6)
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.
Example fix
// before: .svelte-kit/cloudflare/_redirects exists // rm .svelte-kit/cloudflare/_redirects // after // mv .svelte-kit/cloudflare/_redirects static/_redirects
Defensive patterns
Strategy: validation
Validate before calling
import fs from 'node:fs';
if (fs.existsSync('.svelte-kit/cloudflare/_redirects')) {
throw new Error('Move _redirects to static/ so it lands at the deployment root');
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The _headers file should be placed in the project root rathe
- The `edge` runtime is no longer supported
- ${relative} does not exist
- ${relative} is missing ${tag}
- The SvelteKit Vite plugin ${keypath} should be an object wit
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/739210293cb77a89.
Report an issue: GitHub.