{"record":{"id":"ef85356e729ba681","repo":"vercel/next.js","slug":"the-public-directory-is-reserved-in-next-js-and","errorCode":null,"errorMessage":"The 'public' directory is reserved in Next.js and can not be set as the 'distDir'. https://nextjs.org/docs/messages/can-not-output-to-public","messagePattern":"The 'public' directory is reserved in Next\\.js and can not be set as the 'distDir'\\. https://nextjs\\.org/docs/messages/can-not-output-to-public","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/server/config.ts","lineNumber":354,"sourceCode":"    (currentConfig, key) => {\n      const value = (userConfig as any)[key]\n\n      if (value === undefined || value === null) {\n        return currentConfig\n      }\n\n      if (key === 'distDir') {\n        if (typeof value !== 'string') {\n          throw new Error(\n            `Specified distDir is not a string, found type \"${typeof value}\"`\n          )\n        }\n        const userDistDir = value.trim()\n\n        // don't allow public as the distDir as this is a reserved folder for\n        // public files\n        if (userDistDir === 'public') {\n          throw new Error(\n            `The 'public' directory is reserved in Next.js and can not be set as the 'distDir'. https://nextjs.org/docs/messages/can-not-output-to-public`\n          )\n        }\n        // make sure distDir isn't an empty string as it can result in the provided\n        // directory being deleted in development mode\n        if (userDistDir.length === 0) {\n          throw new Error(\n            `Invalid distDir provided, distDir can not be an empty string. Please remove this config or set it to undefined`\n          )\n        }\n      }\n\n      if (key === 'pageExtensions') {\n        if (!Array.isArray(value)) {\n          throw new Error(\n            `Specified pageExtensions is not an array of strings, found \"${value}\". Please update this config or remove it.`\n          )\n        }","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/config.ts#L336-L372","documentation":"Next.js reserves the `public/` directory for serving static files at the site root, so it cannot also be used as `distDir` (the build output directory). Setting `distDir: 'public'` would cause the build to overwrite your static assets. The check is a hard guard in config normalization: any trimmed distDir value equal to 'public' is rejected.","triggerScenarios":"Setting `distDir: 'public'` (or with surrounding whitespace like `' public '`) in next.config.js/ts/mjs. Triggered during loadConfig's reduce step over user config keys.","commonSituations":"Developer wants build output in a known web-served folder and naively picks 'public'. Copy-pasting a config snippet that named the dir 'public'. Migrating from another framework where output went to a public folder.","solutions":["Change distDir to a non-reserved directory name such as '.next' (default) or 'build' or '.output'","If you need static output, use `output: 'export'` instead of pointing distDir at public"],"exampleFix":"// before\nmodule.exports = { distDir: 'public' }\n// after\nmodule.exports = { distDir: '.next' }","handlingStrategy":"validation","validationCode":"if (path.basename(distDir.trim()) === 'public') {\n  throw new Error('distDir cannot be \"public\"')\n}\nconst config = { distDir }","typeGuard":"const isSafeDistDir = (v: unknown): v is string =>\n  typeof v === 'string' && v.trim().length > 0 && v.trim() !== 'public'","tryCatchPattern":null,"preventionTips":["Never name build output 'public'; keep distDir as '.next' or a build-specific folder","Validate env-derived distDir values before passing to next config"],"tags":["config","dist-dir","static-assets"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}