{"record":{"id":"cd4833e57360ed53","repo":"vercel/next.js","slug":"invalid-distdir-provided-distdir-can-not-be-an-em","errorCode":null,"errorMessage":"Invalid distDir provided, distDir can not be an empty string. Please remove this config or set it to undefined","messagePattern":"Invalid distDir provided, distDir can not be an empty string\\. Please remove this config or set it to undefined","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/server/config.ts","lineNumber":361,"sourceCode":"      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        }\n\n        if (!value.length) {\n          throw new Error(\n            `Specified pageExtensions is an empty array. Please update it with the relevant extensions or remove it.`\n          )\n        }\n","sourceCodeStart":343,"sourceCodeEnd":379,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/config.ts#L343-L379","documentation":"An empty `distDir` (or one of only whitespace) is rejected because in development mode an empty path can result in the working directory being wiped. The value is trimmed before the length check, so `'   '` also fails. You must either omit the key entirely or set a real directory name.","triggerScenarios":"Setting `distDir: ''`, `distDir: '   '`, or `distDir: ' \\t '` in next.config. Hit during the reduce-based config merge before defaults are applied.","commonSituations":"Setting distDir from an env var that resolves to empty in some environments (e.g. `distDir: process.env.OUT_DIR`). Templating config with a variable that is undefined.","solutions":["Remove the distDir key entirely to use the default '.next'","Set distDir to undefined explicitly: `distDir: undefined`","Provide a concrete fallback if reading from env: `distDir: process.env.OUT_DIR || '.next'`"],"exampleFix":"// before\nmodule.exports = { distDir: process.env.OUT_DIR }\n// after\nmodule.exports = { distDir: process.env.OUT_DIR || '.next' }","handlingStrategy":"validation","validationCode":"if (typeof distDir === 'string' && distDir.trim().length === 0) {\n  distDir = '.next' // or omit the key\n}","typeGuard":"const isNonEmptyDistDir = (v: unknown): v is string =>\n  typeof v === 'string' && v.trim().length > 0","tryCatchPattern":null,"preventionTips":["Default env-sourced distDir: `distDir: process.env.OUT_DIR || '.next'`","Avoid setting distDir to a variable that can be undefined or empty"],"tags":["config","dist-dir","data-loss"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}