{"record":{"id":"f1054578583444c6","repo":"sveltejs/kit","slug":"the-publish-directory-cannot-be-set-to-the-site-ro","errorCode":null,"errorMessage":"The publish directory cannot be set to the site root. Please change it to another value such as \"build\" in netlify.toml.","messagePattern":"The publish directory cannot be set to the site root\\. Please change it to another value such as \"build\" in netlify\\.toml\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapter-netlify/utils.js","lineNumber":60,"sourceCode":"\t} else {\n\t\treturn b.length === 1 && b[0].rest;\n\t}\n}\n\n/**\n * @param {NetlifyConfig | null} netlify_config\n * @param {import('@sveltejs/kit').Builder} builder\n * @returns {string | undefined}\n */\nexport function get_publish_directory(netlify_config, builder) {\n\tif (netlify_config) {\n\t\tif (!netlify_config.build?.publish) {\n\t\t\tbuilder.log.minor('No publish directory specified in netlify.toml, using default');\n\t\t\treturn;\n\t\t}\n\n\t\tif (resolve(netlify_config.build.publish) === process.cwd()) {\n\t\t\tthrow new Error(\n\t\t\t\t'The publish directory cannot be set to the site root. Please change it to another value such as \"build\" in netlify.toml.'\n\t\t\t);\n\t\t}\n\t\treturn netlify_config.build.publish;\n\t}\n\n\tbuilder.log.warn(\n\t\t'No netlify.toml found. Using default publish directory. Consult https://svelte.dev/docs/kit/adapter-netlify#usage for more details'\n\t);\n}\n\n/**\n * @param {*} value\n * @returns {string}\n */\nexport function s(value) {\n\treturn JSON.stringify(value, null, '\\t');\n}","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/adapter-netlify/utils.js#L42-L78","documentation":"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().","triggerScenarios":"netlify.toml contains `build.publish = \".\"` (or any path that resolves to process.cwd()) when the Netlify adapter builds the project.","commonSituations":"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.","solutions":["Set build.publish to a non-root directory such as \"build\" in netlify.toml","Remove the build.publish key entirely to let the adapter use its default","Ensure the Netlify UI's publish setting matches the value in netlify.toml"],"exampleFix":"// before (netlify.toml)\n[build]\npublish = \".\"\n// after\n[build]\npublish = \"build\"","handlingStrategy":"validation","validationCode":"import { existsSync, readFileSync } from 'node:fs';\nimport { parse } from '@iarna/toml';\nimport { resolve } from 'node:path';\nif (existsSync('netlify.toml')) {\n  const cfg = parse(readFileSync('netlify.toml', 'utf-8'));\n  if (cfg.build?.publish && resolve(cfg.build.publish) === process.cwd()) {\n    throw new Error('build.publish cannot be the site root; use e.g. \"build\"');\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await vite.build();\n} catch (e) {\n  if (e.message.includes('cannot be set to the site root')) {\n    console.error('Change build.publish in netlify.toml to a subdirectory like \"build\"');\n  }\n  throw e;\n}","preventionTips":["Never set build.publish to \".\" for SvelteKit projects","Verify netlify.toml publish matches the adapter's output directory","When migrating from static Netlify sites, audit the existing netlify.toml first"],"tags":["config","netlify","publish-directory"],"backgroundTag":"invalid-publish-directory","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}