{"record":{"id":"5f8dc9227ad1fa26","repo":"angular/angular-cli","slug":"could-not-find-the-main-bundle","errorCode":null,"errorMessage":"Could not find the main bundle.","messagePattern":"Could not find the main bundle\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/build_angular/src/builders/app-shell/index.ts","lineNumber":155,"sourceCode":"  serverResult: ServerBuilderOutput,\n  browserLocaleDirectory: string,\n) {\n  if (options.appModuleBundle) {\n    return path.join(context.workspaceRoot, options.appModuleBundle);\n  }\n\n  const { baseOutputPath = '' } = serverResult;\n  const outputPath = path.join(baseOutputPath, browserLocaleDirectory);\n\n  if (!fs.existsSync(outputPath)) {\n    throw new Error(`Could not find server output directory: ${outputPath}.`);\n  }\n\n  const re = /^main\\.(?:[a-zA-Z0-9]{16}\\.)?js$/;\n  const maybeMain = fs.readdirSync(outputPath).find((x) => re.test(x));\n\n  if (!maybeMain) {\n    throw new Error('Could not find the main bundle.');\n  }\n\n  return path.join(outputPath, maybeMain);\n}\n\nasync function _appShellBuilder(\n  options: BuildWebpackAppShellSchema,\n  context: BuilderContext,\n): Promise<BuilderOutput> {\n  context.logger.warn(\n    'The \"@angular-devkit/build-angular:app-shell\" builder is deprecated as part of Angular\\'s Webpack support deprecation. ' +\n      'Use \"@angular/build:application\" instead. For more information, see https://angular.dev/tools/cli/build-system-migration.',\n  );\n\n  const browserTarget = targetFromTargetString(options.browserTarget);\n  const serverTarget = targetFromTargetString(options.serverTarget);\n\n  // Never run the browser target in watch mode.","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/build_angular/src/builders/app-shell/index.ts#L137-L173","documentation":"After locating the server output directory, the app-shell builder scans it for a file matching /^main\\.(?:[a-zA-Z0-9]{16}\\.)?js$/ to use as the server module bundle for prerendering. If no such file exists, it throws. The server build produced output but not a bundle named main.js (or main.<hash>.js).","triggerScenarios":"The server target was configured with a custom output filename/bundle name (e.g. bundleName set or webpack config renaming main), the server outputPath points at a folder containing nested folders instead of flat bundles, or a different builder (esbuild-based server builder producing different naming) is used as serverTarget.","commonSituations":"Custom webpack builder configs renaming entry bundles; swapping the universal/server target to '@angular/build:application' whose output layout (e.g. server.mjs, subdirectories) no longer matches the webpack-era main.js pattern expected here; poking around dist and moving files.","solutions":["Ensure the server target emits a bundle named main.js (or main.<16-hex-hash>.js) directly in the server output directory.","If using a custom webpack config, keep the 'main' entry/bundle name unchanged.","If using the new application/esbuild server builder, use the app-shell/prerender support of '@angular/build' instead of the webpack app-shell builder, since output naming differs.","Inspect the actual server output directory contents and fix outputPath configuration so it points at the folder containing the main bundle."],"exampleFix":"// before (custom webpack config for server)\noutput: { filename: '[name].bundle.js' }\n// after\noutput: { filename: '[name].js' } // emits main.js","handlingStrategy":"validation","validationCode":"import * as fs from 'fs';\nconst files = fs.readdirSync(serverOutputPath);\nif (!files.some((f) => /^main\\.(?:[a-zA-Z0-9]{16}\\.)?js$/.test(f))) {\n  throw new Error(`No main.js bundle in ${serverOutputPath}: ${files.join(', ')}`);\n}","typeGuard":"const isMainBundle = (f: string) => /^main\\.(?:[a-zA-Z0-9]{16}\\.)?js$/.test(f);","tryCatchPattern":"try {\n  await runAppShell();\n} catch (e) {\n  if (String(e.message) === 'Could not find the main bundle.') {\n    // inspect server output naming, fix webpack output filename or builder choice\n  }\n  throw e;\n}","preventionTips":["Do not rename the 'main' entry bundle in server webpack configs","Match server builder output layout to what app-shell expects","Verify server output directory contents after builds in CI","Prefer @angular/build prerender support with the application builder"],"tags":["angular","app-shell","build","bundle","naming"],"backgroundTag":"main-bundle-not-found","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}