{"record":{"id":"bc0f58641419ab43","repo":"angular/angular-cli","slug":"could-not-find-the-main-bundle-serverbundlepath","errorCode":null,"errorMessage":"Could not find the main bundle: ${serverBundlePath}","messagePattern":"Could not find the main bundle: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/build_angular/src/builders/prerender/index.ts","lineNumber":198,"sourceCode":"\n  const { baseOutputPath = '' } = serverResult;\n  const worker = new Piscina({\n    filename: path.join(__dirname, 'render-worker.js'),\n    maxThreads: maxWorkers,\n    workerData: { zonePackage },\n    recordTiming: false,\n  });\n\n  let routes: string[] | undefined;\n\n  try {\n    // We need to render the routes for each locale from the browser output.\n    for (const { path: outputPath } of browserResult.outputs) {\n      const localeDirectory = path.relative(browserResult.baseOutputPath, outputPath);\n      const serverBundlePath = path.join(baseOutputPath, localeDirectory, 'main.js');\n\n      if (!fs.existsSync(serverBundlePath)) {\n        throw new Error(`Could not find the main bundle: ${serverBundlePath}`);\n      }\n\n      routes ??= await getRoutes(\n        indexFile,\n        outputPath,\n        serverBundlePath,\n        options,\n        context.workspaceRoot,\n      );\n\n      const spinner = ora(`Prerendering ${routes.length} route(s) to ${outputPath}...`).start();\n\n      try {\n        const results = (await Promise.all(\n          routes.map((route) => {\n            const options: RenderOptions = {\n              indexFile,\n              deployUrl: browserOptions.deployUrl || '',","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/build_angular/src/builders/prerender/index.ts#L180-L216","documentation":"During prerendering, after the browser build completes, the prerender builder expects a corresponding server build's `main.js` bundle in the server output directory (per locale). This error is thrown in `_renderUniversal` when `main.js` cannot be found at the computed `serverBundlePath`, meaning the server bundle is missing or named differently. The library throws it because rendering routes requires loading the server bundle to execute Angular Universal.","triggerScenarios":"Running `ng run <project>:prerender` (or dev-server with prerendering/SRG) where `fs.existsSync(serverBundlePath)` fails because the server build output does not contain `main.js` at `<server-output>/<locale-dir>/main.js`.","commonSituations":"The project's server builder output was renamed or the server tsconfig outputs a bundle under a different filename; the server build target was not built or was configured with a different outputPath; custom webpack configuration changes the output filename; cleaning the output directory removed the server bundle; upgrading Angular changed the server bundle filename (e.g. `main.js` vs hashed names).","solutions":["Run the server builder first (ng run <project>:server) and verify `main.js` exists in the server output directory.","Ensure `prerender` target's `browserTarget` and `serverTarget` point at configurations whose outputPath matches and whose output is not hashed/renamed.","Check the server tsconfig/webpack config for custom output filenames and restore `main.js` as the bundle name.","Delete the output folder and rebuild both browser and server targets to rule out stale/corrupt output."],"exampleFix":"// angular.json - prerender target pointing only at browser build\n\"options\": { \"browserTarget\": \"app:build\" }\n// after: include the server target output and default filenames\n\"options\": { \"browserTarget\": \"app:build\", \"serverTarget\": \"app:server\" }","handlingStrategy":"validation","validationCode":"import * as fs from 'fs';\nimport * as path from 'path';\nconst serverBundlePath = path.join(serverOutputPath, localeDir ?? '', 'main.js');\nif (!fs.existsSync(serverBundlePath)) {\n  throw new Error(`Run the server target first; missing bundle: ${serverBundlePath}`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always build the server target (ng run project:server) before prerender.","Do not customize webpack output filenames for the server bundle.","Keep serverTarget/browserTarget output paths consistent in angular.json."],"tags":["angular","prerender","universal","missing-file","build"],"backgroundTag":"server-bundle-not-found","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}