vercel/next.js · error · Error
The 'public' directory is reserved in Next.js and can not…
Error message
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
What it means
Config validation in assignDefaultsAndValidate: the distDir string, after trimming, equals 'public'. The public directory is reserved for static assets served from the site root — using it as the build output directory would collide with user files, so the value is rejected outright.
Solutions
- Choose a different distDir; 'public' is reserved.
Defensive patterns
Strategy: validation
When it happens
Trigger: distDir is set to the reserved public directory.
Common situations: Configuring distDir: 'public' in next.config, which conflicts with Next.js static serving.
AI-assisted analysis of vercel/next.js@34433fd12e (2026-08-19).
Data as JSON: /api/errors/ef85356e729ba681.
Report an issue: GitHub.
Appendix: source
Thrown at packages/next/src/server/config.ts:389
(currentConfig, key) => {
const value = (userConfig as any)[key]
if (value === undefined || value === null) {
return currentConfig
}
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.`
)
}View on GitHub (pinned to 34433fd12e)