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

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.

Source

Thrown at packages/adapter-netlify/index.js:53

export default function ({ split = false, edge = edge_set_in_env_var } = {}) {
	return {
		name,
		async adapt(builder) {
			if (!builder.routes) {
				throw new Error(
					'@sveltejs/adapter-netlify >=2.x (possibly installed through @sveltejs/adapter-auto) requires @sveltejs/kit version 1.5 or higher. ' +
						'Either downgrade the adapter or upgrade @sveltejs/kit'
				);
			}

			if (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 (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 netlify_config = get_netlify_config();

			// "build" is the default publish directory when Netlify detects SvelteKit
			const publish = get_publish_directory(netlify_config, builder) || 'build';

			// empty out existing build directories
			rmSync(publish, { force: true, recursive: true });
			rmSync('.netlify/v1', { force: true, recursive: true });

			// clean up legacy directories from older adapter versions to avoid
			// gnarly edge cases when an existing project is upgraded to this version
			rmSync('.netlify/edge-functions', { force: true, recursive: true });
			rmSync('.netlify/server', { force: true, recursive: true });
			rmSync('.netlify/package.json', { force: true, recursive: true });

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Move _redirects from the static directory to the project root
  2. Express the redirects in SvelteKit's own routing (src/routes) where possible, or keep them in the root _redirects the adapter copies to publish
  3. Delete static/_redirects if it duplicates rules handled by the adapter

Example fix

// shell
git mv static/_redirects ./_redirects
Defensive patterns

Strategy: validation

Validate before calling

import { existsSync } from 'node:fs';
if (existsSync('static/_redirects')) throw new Error('Move static/_redirects to the project root');

Prevention

When it happens

Trigger: A file named _redirects exists in kit.files.assets (usually `static`) when the Netlify adapter runs adapt().

Common situations: Migrating from a non-SvelteKit Netlify setup that kept _redirects in the public folder; copying Netlify starter files into static/; following outdated tutorials.

Related errors


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/f3a4fe465c660e09. Report an issue: GitHub.