vercel/next.js · error · Error
Invalid distDir provided, distDir can not be an empty string
Error message
Invalid distDir provided, distDir can not be an empty string. Please remove this config or set it to undefined
What it means
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.
Source
Thrown at packages/next/src/server/config.ts:361
if (key === 'distDir') {
if (typeof value !== 'string') {
throw new Error(
`Specified distDir is not a string, found type "${typeof value}"`
)
}
const userDistDir = value.trim()
// don't allow public as the distDir as this is a reserved folder for
// public files
if (userDistDir === 'public') {
throw new Error(
`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`
)
}
// make sure distDir isn't an empty string as it can result in the provided
// directory being deleted in development mode
if (userDistDir.length === 0) {
throw new Error(
`Invalid distDir provided, distDir can not be an empty string. Please remove this config or set it to undefined`
)
}
}
if (key === 'pageExtensions') {
if (!Array.isArray(value)) {
throw new Error(
`Specified pageExtensions is not an array of strings, found "${value}". Please update this config or remove it.`
)
}
if (!value.length) {
throw new Error(
`Specified pageExtensions is an empty array. Please update it with the relevant extensions or remove it.`
)
}
View on GitHub (pinned to 0ae8c72462)
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'`
Example fix
// before
module.exports = { distDir: process.env.OUT_DIR }
// after
module.exports = { distDir: process.env.OUT_DIR || '.next' } Defensive patterns
Strategy: validation
Validate before calling
if (typeof distDir === 'string' && distDir.trim().length === 0) {
distDir = '.next' // or omit the key
} Type guard
const isNonEmptyDistDir = (v: unknown): v is string => typeof v === 'string' && v.trim().length > 0
Prevention
- Default env-sourced distDir: `distDir: process.env.OUT_DIR || '.next'`
- Avoid setting distDir to a variable that can be undefined or empty
When it happens
Trigger: Setting `distDir: ''`, `distDir: ' '`, or `distDir: ' \t '` in next.config. Hit during the reduce-based config merge before defaults are applied.
Common situations: 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.
Related errors
- The 'public' directory is reserved in Next.js and can not be
- `forbidden()` is experimental and only allowed to be enabled
- `unauthorized()` is experimental and only allowed to be used
- NEXT_EXPORT_ERROR
- Failed to resolve pattern "${patterns.join(',')}": ${error.m
AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06).
Data as JSON: /api/errors/cd4833e57360ed53.
Report an issue: GitHub.