sveltejs/kit · error · Error

The publish directory cannot be set to the site root. Please

Error message

The publish directory cannot be set to the site root. Please change it to another value such as "build" in netlify.toml.

What it means

Netlify's build.publish directory is where adapter-netlify writes the deployable output. If netlify.toml sets build.publish to the site root ('.'), the adapter would overwrite repository source files and Netlify cannot publish the root, so get_publish_directory throws during adapt().

Source

Thrown at packages/adapter-netlify/utils.js:60

	} else {
		return b.length === 1 && b[0].rest;
	}
}

/**
 * @param {NetlifyConfig | null} netlify_config
 * @param {import('@sveltejs/kit').Builder} builder
 * @returns {string | undefined}
 */
export function get_publish_directory(netlify_config, builder) {
	if (netlify_config) {
		if (!netlify_config.build?.publish) {
			builder.log.minor('No publish directory specified in netlify.toml, using default');
			return;
		}

		if (resolve(netlify_config.build.publish) === process.cwd()) {
			throw new Error(
				'The publish directory cannot be set to the site root. Please change it to another value such as "build" in netlify.toml.'
			);
		}
		return netlify_config.build.publish;
	}

	builder.log.warn(
		'No netlify.toml found. Using default publish directory. Consult https://svelte.dev/docs/kit/adapter-netlify#usage for more details'
	);
}

/**
 * @param {*} value
 * @returns {string}
 */
export function s(value) {
	return JSON.stringify(value, null, '\t');
}

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Set build.publish to a non-root directory such as "build" in netlify.toml
  2. Remove the build.publish key entirely to let the adapter use its default
  3. Ensure the Netlify UI's publish setting matches the value in netlify.toml

Example fix

// before (netlify.toml)
[build]
publish = "."
// after
[build]
publish = "build"
Defensive patterns

Strategy: validation

Validate before calling

import { existsSync, readFileSync } from 'node:fs';
import { parse } from '@iarna/toml';
import { resolve } from 'node:path';
if (existsSync('netlify.toml')) {
  const cfg = parse(readFileSync('netlify.toml', 'utf-8'));
  if (cfg.build?.publish && resolve(cfg.build.publish) === process.cwd()) {
    throw new Error('build.publish cannot be the site root; use e.g. "build"');
  }
}

Try / catch

try {
  await vite.build();
} catch (e) {
  if (e.message.includes('cannot be set to the site root')) {
    console.error('Change build.publish in netlify.toml to a subdirectory like "build"');
  }
  throw e;
}

Prevention

When it happens

Trigger: netlify.toml contains `build.publish = "."` (or any path that resolves to process.cwd()) when the Netlify adapter builds the project.

Common situations: Copying config from static-site Netlify setups where publish = "." is valid; forgetting to change the publish dir after migrating to SvelteKit; Netlify UI default site settings conflicting with expectations.

Related errors


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