{"record":{"id":"4a918e0c60dc71d4","repo":"vercel/next.js","slug":"no-next-js-app-found-in-this-directory-run-the-command-from","errorCode":null,"errorMessage":"No Next.js app found in this directory. Run the command from an app directory or pass its path.","messagePattern":"No Next\\.js app found in this directory\\. Run the command from an app directory or pass its path\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/cli/next-upgrade.ts","lineNumber":185,"sourceCode":"          baseDir,\n          aiArgument,\n        ]\n\n        if (options.verbose) {\n          args.push('--verbose')\n        }\n\n        process.exitCode = await runChildProcess(command, args, {\n          cwd: baseDir,\n          stdio: 'inherit',\n          env: { ...process.env, __NEXT_UPGRADE_USE_CURRENT_CLI: '1' },\n        })\n        return\n      }\n\n      // A workspace root must not launch an upgrade for an unspecified app.\n      if (!findDir(baseDir, 'app') && !findDir(baseDir, 'pages')) {\n        throw new Error(\n          'No Next.js app found in this directory. Run the command from an app directory or pass its path.'\n        )\n      }\n\n      const upgradeType = await resolveAIUpgradeType(baseDir, options.ai)\n\n      if (\n        upgradeType !== 'security' &&\n        upgradeType !== 'latest' &&\n        upgradeType !== 'future'\n      ) {\n        throw new Error(\n          `Unsupported AI upgrade type ${JSON.stringify(upgradeType)}. Expected \"security\", \"latest\", or \"future\".`\n        )\n      }\n\n      // Resolve the requested target before preparing an agent session.\n      const { prepareUpgrade } =","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/vercel/next.js/blob/34433fd12ee8074ea3f47af9f36255c7390d0301/packages/next/src/cli/next-upgrade.ts#L167-L203","documentation":"The AI upgrade path refuses to launch an agent session unless the resolved directory actually contains a Next.js app (an 'app' or 'pages' directory). getProjectDir falls back to the current working directory when no path is passed, so running `next upgrade --ai` from a workspace root or a non-Next.js folder triggers this.","triggerScenarios":"Running `next upgrade --ai` (or `--ai=<type>`) from a directory with no app/ or pages/ directory (monorepo root, empty folder, or a non-app subdirectory) without passing an explicit app path.","commonSituations":"Running the command in a monorepo root where apps live in apps/web; running in a repo that only has a src/app layout the finder does not see (rare) or before scaffolding an app.","solutions":["cd into the app directory (the one containing app/ or pages/) and rerun `next upgrade --ai`","Pass the app path explicitly: `next upgrade --ai <path-to-app>`","Verify the app uses the app/ or pages/ directory at its root (or src/app|src/pages)","If in a monorepo, target the specific workspace directory"],"exampleFix":"// before\nnext upgrade --ai   # run from repo root, no app/ here\n// after\nnext upgrade --ai apps/web","handlingStrategy":"validation","validationCode":"const fs = require('fs'); const path = require('path')\nfunction isNextAppDir(dir) {\n  return ['app','pages','src/app','src/pages'].some(p => fs.existsSync(path.join(dir, p)))\n}\nif (!isNextAppDir(process.cwd())) console.error('Run from an app directory or pass its path')","typeGuard":null,"tryCatchPattern":"try {\n  await spawnNextUpgrade(directory, options)\n} catch (e) {\n  if (e.message.includes('No Next.js app found')) {\n    // prompt user to cd into the app or pass a path\n  }\n}","preventionTips":["Run next upgrade from the directory containing app/ or pages/","In monorepos, always pass the app path explicitly","Script wrappers should locate the app dir before invoking the CLI"],"tags":["nextjs","cli","upgrade","directory"],"backgroundTag":"directory-not-found","analyzedSha":"34433fd12ee8074ea3f47af9f36255c7390d0301","analyzedAt":"2026-09-20T18:20:20.576Z","contentChangedAt":"2026-09-20T18:20:20.576Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}