{"record":{"id":"cccdc6dba495fc9f","repo":"vercel/next.js","slug":"failed-to-find-the-root-directory-of-the-project","errorCode":null,"errorMessage":"Failed to find the root directory of the project. This is a bug in Next.js.","messagePattern":"Failed to find the root directory of the project\\. This is a bug in Next\\.js\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/next/src/server/config.ts","lineNumber":1187,"sourceCode":"  // If both provided, validate they match. If not, use outputFileTracingRoot.\n  if (tracingRoot && turbopackRoot && tracingRoot !== turbopackRoot) {\n    Log.warn(\n      `Both \\`outputFileTracingRoot\\` and \\`turbopack.root\\` are set, but they must have the same value.\\n` +\n        `Using \\`outputFileTracingRoot\\` value: ${tracingRoot}.`\n    )\n  }\n  let rootDir = tracingRoot || turbopackRoot\n  if (!rootDir) {\n    rootDir = repoRoot\n    if (rootDirResult && !silent) {\n      if (rootDirResult.boundary) {\n        warnRootBoundary(rootDirResult.boundary)\n      }\n      warnDuplicatedLockFiles(rootDirResult.lockFiles)\n    }\n  }\n  if (!rootDir) {\n    throw new Error(\n      'Failed to find the root directory of the project. This is a bug in Next.js.'\n    )\n  }\n  // Ensure both properties are set to the same value\n  result.outputFileTracingRoot = rootDir\n  dset(result, ['turbopack', 'root'], rootDir)\n\n  setHttpClientAndAgentOptions(result || defaultConfig)\n\n  if (result.i18n) {\n    const { i18n } = result\n    const i18nType = typeof i18n\n\n    if (i18nType !== 'object') {\n      throw new Error(\n        `Specified i18n should be an object received ${i18nType}.\\nSee more info here: https://nextjs.org/docs/messages/invalid-i18n-config`\n      )\n    }","sourceCodeStart":1169,"sourceCodeEnd":1205,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/config.ts#L1169-L1205","documentation":"Next.js determines the project root (for file tracing and lock-file warnings) via `findRootDirAndLockFiles(dir)` unless NEXT_PRIVATE_OUTPUT_TRACE_ROOT is set or outputFileTracingRoot/turbopack.root is provided (config.ts:1158-1190). If none of these resolve to a rootDir, it throws because standalone tracing cannot proceed. The message explicitly calls this a Next.js bug because, under normal circumstances, a root should always be found.","triggerScenarios":"Building in an unusual filesystem layout (no package.json/lockfile upward from the project dir), an unreadable filesystem, a permissions error during findRootDirAndLockFiles, or a broken node module install. Setting neither outputFileTracingRoot, turbopack.root, nor NEXT_PRIVATE_OUTPUT_TRACE_ROOT.","commonSituations":"Running `next build` in a throwaway container or sandbox with a stripped workspace. A repo restructure that removed the lockfile. Permission errors on parent directories. A genuine regression in findRootDirAndLockFiles.","solutions":["Set `outputFileTracingRoot` in next.config to the absolute repo root as a workaround: `outputFileTracingRoot: __dirname`.","Or set the env var `NEXT_PRIVATE_OUTPUT_TRACE_ROOT=/path/to/repo` for the build.","If neither applies, file a Next.js bug with your directory layout and the output of `find . -maxdepth 2 -name 'package.json'`."],"exampleFix":"// before\nmodule.exports = {}\n// after\nconst path = require('path')\nmodule.exports = { outputFileTracingRoot: path.join(__dirname) }","handlingStrategy":"fallback","validationCode":"const fs = require('fs'); const path = require('path');\nfunction findUp(start, name) {\n  let dir = path.resolve(start);\n  while (true) { const cand = path.join(dir, name); if (fs.existsSync(cand)) return cand; const parent = path.dirname(dir); if (parent === dir) return null; dir = parent; }\n}\nif (!findUp(__dirname, 'package.json')) {\n  console.warn('No package.json upward; set outputFileTracingRoot to avoid root-detection failure.');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set outputFileTracingRoot in containerized or sandboxed builds.","Keep a lockfile (package-lock.json / pnpm-lock.yaml / yarn.lock) at the repo root.","Set NEXT_PRIVATE_OUTPUT_TRACE_ROOT as a CI escape hatch when root detection is unreliable."],"tags":["config","file-tracing","standalone","bug","next-config"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}