---
title: Invalid distDir
url: "https://nextjs.org/docs/messages/invalid-dist-dir"
docs_index: /docs/llms.txt
---



## 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:

```js filename="next.config.js"
module.exports = {
  distDir: 'build',
}
```

## Useful Links

- [`distDir` configuration](/docs/app/api-reference/config/next-config-js/distDir)
