invalid-dist-dir.mdx


title: Invalid distDir

Why This Error Occurred

Next.js takes full ownership of the directory configured as distDir (.next by default). Builds and development sessions write output there and normally delete stale contents. To protect against data loss, Next.js refuses to use the directory when it:

  • resolves outside both the application directory (the one holding next.config.js) and the workspace root containing it; or
  • is the application directory itself or one of its ancestors.

Pointing distDir elsewhere inside the workspace is supported when the output does not contain the application. For example, an application at apps/web may use distDir: '../.next'.

Possible Ways to Fix It

Point distDir at a dedicated directory inside the application or workspace:

module.exports = {
  distDir: 'build',
}

Rendered from the public repository vercel/next.js on GitHub; content belongs to its authors. Cached for up to an hour.

errors/invalid-dist-dir.mdx · vercel/next.js | Docs MD