vercel/next.js · error · Error

> Couldn't find any `pages` or `app` directory. Please…

Error message

> Couldn't find any `pages` or `app` directory. Please create one under the project root

What it means

Project layout validation in findPagesDir: neither a pages/ nor an app/ directory was found at the project root or under src/. Next.js has no routes to serve, so startup fails with this error rather than serving an empty application.

Solutions

  1. Create a pages/ or app/ directory at the project root (or under src/).
Defensive patterns

Strategy: validation

When it happens

Trigger: Next.js cannot find a pages or app directory at startup.

Common situations: Running next dev/build in a project missing both pages/ and app/ directories or with wrong root.


AI-assisted analysis of vercel/next.js@0eb3775416 (2026-08-19). Data as JSON: /api/errors/b3534a91e7c780a5. Report an issue: GitHub.

Appendix: source

Thrown at packages/next/src/lib/find-pages-dir.ts:23

  // prioritize ./${name} over ./src/${name}
  let curDir = path.join(dir, name)
  if (fs.existsSync(curDir)) return curDir

  curDir = path.join(dir, 'src', name)
  if (fs.existsSync(curDir)) return curDir

  return null
}

export function findPagesDir(dir: string): {
  pagesDir: string | undefined
  appDir: string | undefined
} {
  const pagesDir = findDir(dir, 'pages') || undefined
  const appDir = findDir(dir, 'app') || undefined

  if (appDir == null && pagesDir == null) {
    throw new Error(
      "> Couldn't find any `pages` or `app` directory. Please create one under the project root"
    )
  }

  if (pagesDir && appDir) {
    const pagesParent = path.dirname(pagesDir)
    const appParent = path.dirname(appDir)
    if (pagesParent !== appParent) {
      throw new Error(
        '> `pages` and `app` directories should be under the same folder'
      )
    }
  }

  return {
    pagesDir,
    appDir,
  }

View on GitHub (pinned to 0eb3775416)