{"record":{"id":"3291588ae4fc1376","repo":"angular/angular-cli","slug":"the-builder-requires-a-target-329158","errorCode":null,"errorMessage":"The builder requires a target.","messagePattern":"The builder requires a target\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/build_angular/src/utils/webpack-browser-config.ts","lineNumber":139,"sourceCode":"              hash.update('$localize' + i18nHash);\n            },\n          );\n        });\n      },\n    });\n  }\n\n  return { ...result, i18n };\n}\nexport async function generateBrowserWebpackConfigFromContext(\n  options: BrowserBuilderSchema,\n  context: BuilderContext,\n  webpackPartialGenerator: WebpackPartialGenerator,\n  extraBuildOptions: Partial<NormalizedBrowserBuilderSchema> = {},\n): Promise<{ config: Configuration; projectRoot: string; projectSourceRoot?: string }> {\n  const projectName = context.target && context.target.project;\n  if (!projectName) {\n    throw new Error('The builder requires a target.');\n  }\n\n  const workspaceRoot = context.workspaceRoot;\n  const projectMetadata = await context.getProjectMetadata(projectName);\n  const projectRoot = path.join(workspaceRoot, (projectMetadata.root as string | undefined) ?? '');\n  const sourceRoot = projectMetadata.sourceRoot as string | undefined;\n  const projectSourceRoot = sourceRoot ? path.join(workspaceRoot, sourceRoot) : undefined;\n\n  const normalizedOptions = normalizeBrowserSchema(\n    workspaceRoot,\n    projectRoot,\n    projectSourceRoot,\n    options,\n    projectMetadata,\n    context.logger,\n  );\n\n  const config = await generateWebpackConfig(","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/build_angular/src/utils/webpack-browser-config.ts#L121-L157","documentation":"generateBrowserWebpackConfigFromContext needs the architect target (project name) to load project metadata and resolve the project root. When context.target is null — i.e. the builder was invoked outside the normal architect target execution flow — it throws 'The builder requires a target.'. It is an invocation-context validation error, not a code or config content problem.","triggerScenarios":"Calling executeBrowserBuilder (or this builder) programmatically with a context lacking a target; scheduling a builder without specifying project/target in architect.scheduleTarget; a corrupted angular.json entry missing the project the target refers to.","commonSituations":"Custom scripts invoking builders via the BuilderHost API, test harnesses creating mock BuilderContext objects without setting target, dynamic target composition where project name is lost.","solutions":["Schedule the builder through architect.scheduleTarget({ project, target | configuration }) with an explicit project name","If invoking programmatically, set context.target = { project: '<project>', target: '<target>', builder: '<builder:target>' } on your context","Verify the target's project exists in angular.json and the file parses correctly"],"exampleFix":"// before\ncontext.scheduleBuilder('@angular-devkit/build-angular:browser', options);\n// after\ncontext.scheduleTarget({ project: 'my-app', target: 'build' }, options);","handlingStrategy":"validation","validationCode":"// Before scheduling/executing the builder:\nif (!context.target || !context.target.project) {\n  throw new Error('The builder requires a target: schedule via architect.scheduleTarget({ project, target }).');\n}\nconst projectNames = Object.keys(require('./angular.json').projects);\nif (!projectNames.includes(context.target.project)) {\n  throw new Error(`Unknown project ${context.target.project}; known: ${projectNames.join(', ')}`);\n}","typeGuard":"function hasArchitectTarget(ctx: { target?: { project?: string } | null }): ctx is { target: { project: string } } {\n  return typeof ctx.target?.project === 'string' && ctx.target.project.length > 0;\n}","tryCatchPattern":"try {\n  const { config } = await generateBrowserWebpackConfigFromContext(...);\n} catch (e) {\n  if ((e as Error).message === 'The builder requires a target.') {\n    throw new Error('Invoke this builder through an architect target (ng build / scheduleTarget), not bare scheduleBuilder.');\n  }\n  throw e;\n}","preventionTips":["Always schedule builders with scheduleTarget including an explicit project name","In test harnesses, populate mock context.target before calling builder logic","Keep angular.json valid; a missing project entry can null out target resolution"],"tags":["angular-cli","architect","builder-context","configuration"],"backgroundTag":"missing-architect-target","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}