{"record":{"id":"0f38aa2d2abd173b","repo":"vercel/next.js","slug":"could-not-find-a-production-build-in-the-opts-c","errorCode":null,"errorMessage":"Could not find a production build in the '${opts.config.distDir}' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id","messagePattern":"Could not find a production build in the '(.+?)' directory\\. Try building your app with 'next build' before starting the production server\\. https://nextjs\\.org/docs/messages/production-start-no-build-id","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/next/src/server/lib/router-utils/filesystem.ts","lineNumber":201,"sourceCode":"    redirects: [],\n    rewrites: {\n      beforeFiles: [],\n      afterFiles: [],\n      fallback: [],\n    },\n    onMatchHeaders: [],\n    headers: [],\n  }\n  let buildId = 'development'\n  let previewProps: __ApiPreviewProps\n\n  if (!opts.dev) {\n    const buildIdPath = path.join(opts.dir, opts.config.distDir, BUILD_ID_FILE)\n    try {\n      buildId = await fs.readFile(buildIdPath, 'utf8')\n    } catch (err: any) {\n      if (err.code !== 'ENOENT') throw err\n      throw new Error(\n        `Could not find a production build in the '${opts.config.distDir}' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id`\n      )\n    }\n\n    try {\n      for (const file of await recursiveReadDir(publicFolderPath)) {\n        // Ensure filename is encoded and normalized.\n        publicFolderItems.add(encodeURIPath(normalizePathSep(file)))\n      }\n    } catch (err: any) {\n      if (err.code !== 'ENOENT') {\n        throw err\n      }\n    }\n\n    try {\n      for (const file of await recursiveReadDir(legacyStaticFolderPath)) {\n        // Ensure filename is encoded and normalized.","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/lib/router-utils/filesystem.ts#L183-L219","documentation":"Thrown by the production router filesystem setup when it cannot read the BUILD_ID file from the configured distDir. The build ID file is the marker that a `next build` has completed; its absence (ENOENT) means no production build exists in that directory.","triggerScenarios":"Running `next start` (or a production server) without first running `next build`, or with a custom distDir that points somewhere the build output isn't. The readFile of BUILD_ID throws ENOENT.","commonSituations":"Deploying without a build step, CI that runs start before build, a Docker image that copied source but not .next, or a misconfigured distDir (e.g. 'out' while build wrote to '.next'). Deleting .next between build and start.","solutions":["Run `next build` before `next start` in the same directory.","Verify distDir in next.config.js matches the directory containing the build output.","In Docker/CI, ensure the build output (e.g. .next) is present in the image/stage where the server starts.","Do not delete or git-ignore the BUILD_ID file inside distDir."],"exampleFix":"// before: starting without building\nnext start\n\n// after: build then start\nnext build && next start","handlingStrategy":"validation","validationCode":"import fs from 'fs'\nimport path from 'path'\nconst buildId = path.join(process.cwd(), '.next', 'BUILD_ID')\nif (!fs.existsSync(buildId)) {\n  throw new Error('Run `next build` before `next start`')\n}","typeGuard":"import fs from 'fs'\nfunction hasProductionBuild(distDir: string): boolean {\n  return fs.existsSync(path.join(distDir, 'BUILD_ID'))\n}","tryCatchPattern":"null","preventionTips":["Always run `next build` before `next start`.","Include the full distDir in Docker images / deploy artifacts.","Keep distDir consistent between build and start."],"tags":["production","build","dist-dir","deployment"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}