{"record":{"id":"b3534a91e7c780a5","repo":"vercel/next.js","slug":"couldn-t-find-any-pages-or-app-directory-pl","errorCode":null,"errorMessage":"> Couldn't find any `pages` or `app` directory. Please create one under the project root","messagePattern":"> Couldn't find any `pages` or `app` directory\\. Please create one under the project root","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/next/src/lib/find-pages-dir.ts","lineNumber":23,"sourceCode":"  // prioritize ./${name} over ./src/${name}\n  let curDir = path.join(dir, name)\n  if (fs.existsSync(curDir)) return curDir\n\n  curDir = path.join(dir, 'src', name)\n  if (fs.existsSync(curDir)) return curDir\n\n  return null\n}\n\nexport function findPagesDir(dir: string): {\n  pagesDir: string | undefined\n  appDir: string | undefined\n} {\n  const pagesDir = findDir(dir, 'pages') || undefined\n  const appDir = findDir(dir, 'app') || undefined\n\n  if (appDir == null && pagesDir == null) {\n    throw new Error(\n      \"> Couldn't find any `pages` or `app` directory. Please create one under the project root\"\n    )\n  }\n\n  if (pagesDir && appDir) {\n    const pagesParent = path.dirname(pagesDir)\n    const appParent = path.dirname(appDir)\n    if (pagesParent !== appParent) {\n      throw new Error(\n        '> `pages` and `app` directories should be under the same folder'\n      )\n    }\n  }\n\n  return {\n    pagesDir,\n    appDir,\n  }","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/lib/find-pages-dir.ts#L5-L41","documentation":"Thrown by findPagesDir() when neither a `pages` nor an `app` directory can be located under the project root (or ./src/). Next.js needs at least one routing directory to know what to build; with both absent it cannot infer routes and aborts before wasted work.","triggerScenarios":"Running `next dev`/`next build` in a directory that has no pages/ or app/ folder (and no src/pages or src/app). The lookup checks ./pages, ./src/pages, ./app, ./src/app in that priority.","commonSituations":"Wrong working directory (running Next from a parent folder); a fresh project where the routing directory was gitignored or never created; a monorepo where the command is executed at the workspace root rather than the app package; or after renaming pages/ to routes/ by mistake.","solutions":["Create an `app/` (recommended) or `pages/` directory at the project root, or under `src/`.","Confirm you are running the Next.js command from the directory that contains the routing folder, not a parent or sibling.","In a monorepo, run the command via the package filter (`pnpm --filter=myapp dev`) or set cwd correctly.","If using a custom src dir, ensure next.config.js srcDir (if set) and the actual folder layout agree."],"exampleFix":"# before: project root has neither pages/ nor app/\nls # -> next.config.js package.json (no routing dir)\nnext dev  # error\n# after\nmkdir app && echo 'export default function Page(){return <p>hi</p>}' > app/page.tsx\nnext dev","handlingStrategy":"validation","validationCode":"import fs from 'fs'\nimport path from 'path'\nfunction assertRoutingDirExists(root: string) {\n  const candidates = ['pages', 'src/pages', 'app', 'src/app']\n  if (!candidates.some((c) => fs.existsSync(path.join(root, c)))) {\n    throw new Error('No pages/ or app/ directory found under ' + root)\n  }\n}","typeGuard":"function hasRoutingDir(root: string): boolean {\n  return ['pages','src/pages','app','src/app'].some((c) =>\n    fs.existsSync(path.join(root, c)))\n}","tryCatchPattern":null,"preventionTips":["Scaffold new projects with create-next-app which creates app/ by default.","In monorepos, run Next.js from the app package directory, not the workspace root.","Gitignore .next but never the routing directory.","Add a prebuild script that asserts a routing directory exists."],"tags":["project-structure","routing","build","configuration"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}