vercel/next.js · error · Error
No Next.js app found in this directory. Run the command…
Error message
No Next.js app found in this directory. Run the command from an app directory or pass its path.
What it means
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.
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
Example fix
// before next upgrade --ai # run from repo root, no app/ here // after next upgrade --ai apps/web
Defensive patterns
Strategy: validation
Validate before calling
const fs = require('fs'); const path = require('path')
function isNextAppDir(dir) {
return ['app','pages','src/app','src/pages'].some(p => fs.existsSync(path.join(dir, p)))
}
if (!isNextAppDir(process.cwd())) console.error('Run from an app directory or pass its path') Try / catch
try {
await spawnNextUpgrade(directory, options)
} catch (e) {
if (e.message.includes('No Next.js app found')) {
// prompt user to cd into the app or pass a path
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not prepare an upgrade retry. This command will…
- Could not prepare upgrade document
- Unsupported AI upgrade type
- ${warning}
- AI upgrades are not available for prerelease versions of…
AI-assisted analysis of vercel/next.js@34433fd12e (2026-09-20).
Data as JSON: /api/errors/4a918e0c60dc71d4.
Report an issue: GitHub.
Appendix: source
Thrown at packages/next/src/cli/next-upgrade.ts:185
baseDir,
aiArgument,
]
if (options.verbose) {
args.push('--verbose')
}
process.exitCode = await runChildProcess(command, args, {
cwd: baseDir,
stdio: 'inherit',
env: { ...process.env, __NEXT_UPGRADE_USE_CURRENT_CLI: '1' },
})
return
}
// A workspace root must not launch an upgrade for an unspecified app.
if (!findDir(baseDir, 'app') && !findDir(baseDir, 'pages')) {
throw new Error(
'No Next.js app found in this directory. Run the command from an app directory or pass its path.'
)
}
const upgradeType = await resolveAIUpgradeType(baseDir, options.ai)
if (
upgradeType !== 'security' &&
upgradeType !== 'latest' &&
upgradeType !== 'future'
) {
throw new Error(
`Unsupported AI upgrade type ${JSON.stringify(upgradeType)}. Expected "security", "latest", or "future".`
)
}
// Resolve the requested target before preparing an agent session.
const { prepareUpgrade } =View on GitHub (pinned to 34433fd12e)