{"record":{"id":"98a32fa4ed53ad86","repo":"vercel/next.js","slug":"pages-and-app-directories-should-be-under-th","errorCode":null,"errorMessage":"> `pages` and `app` directories should be under the same folder","messagePattern":"> `pages` and `app` directories should be under the same folder","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/lib/find-pages-dir.ts","lineNumber":32,"sourceCode":"\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  }\n}\n","sourceCodeStart":14,"sourceCodeEnd":43,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/lib/find-pages-dir.ts#L14-L43","documentation":"Thrown by findPagesDir() when both a `pages` and an `app` directory exist but their parent directories differ. Next.js requires both routing roots to share the same parent folder so route resolution is unambiguous; mixing locations (e.g. pages/ at root and app/ under src/) breaks the shared route namespace.","triggerScenarios":"The project has, for example, ./pages and ./src/app, or ./src/pages and ./app. path.dirname of each differs, triggering the guard. Common during incremental migration from Pages Router to App Router.","commonSituations":"Migrating to the App Router by creating app/ inside src/ while the old pages/ remains at the root; scaffolding tools that put one router under src and another at root; or a half-finished restructure. Also after moving source into src/ and forgetting to relocate one of the routing folders.","solutions":["Move both directories under the same parent (either both at root: ./pages + ./app, or both under src: ./src/pages + ./src/app).","Delete the unused router folder if you have fully migrated (e.g. remove pages/ once app/ is the source of truth).","Verify there are no stale copies of pages/ or app/ left behind by a move operation."],"exampleFix":"# before: mismatched parents\n# ./pages/            <- root\n# ./src/app/          <- src\nnext dev  # error\n# after: align both under src\nmv pages src/pages\n# now ./src/pages and ./src/app share parent\nnext dev","handlingStrategy":"validation","validationCode":"import fs from 'fs'\nimport path from 'path'\nfunction assertRoutingDirsColocated(root: string) {\n  const pages = ['pages','src/pages'].map((c)=>path.join(root,c)).find(fs.existsSync)\n  const app = ['app','src/app'].map((c)=>path.join(root,c)).find(fs.existsSync)\n  if (pages && app && path.dirname(pages) !== path.dirname(app)) {\n    throw new Error('pages/ and app/ must share the same parent directory')\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["During Pages→App migration, keep both routers under the same parent (root or src).","After migration, delete the unused router folder to avoid ambiguity.","Add a lint/prebuild check that compares dirname(pages) and dirname(app)."],"tags":["project-structure","routing","migration","build"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}