angular/angular-cli · error · Error

The builder requires a target.

Error message

The builder requires a target.

What it means

buildWebpackBrowser requires an Architect target context (context.target.project) to resolve workspace configuration and options. Builders invoked outside a valid architect target context have no project, so the builder throws immediately before doing any work. It also warns that the browser builder is deprecated in favor of '@angular/build:application'.

Source

Thrown at packages/angular_devkit/build_angular/src/builders/browser/index.ts:129

  return { config: transformedConfig || config, projectRoot, projectSourceRoot, i18n };
}

/**
 * @experimental Direct usage of this function is considered experimental.
 */
export function buildWebpackBrowser(
  options: BrowserBuilderSchema,
  context: BuilderContext,
  transforms: {
    webpackConfiguration?: ExecutionTransformer<webpack.Configuration>;
    logging?: WebpackLoggingCallback;
    indexHtml?: IndexHtmlTransform;
  } = {},
): Observable<BrowserBuilderOutput> {
  const projectName = context.target?.project;
  if (!projectName) {
    throw new Error('The builder requires a target.');
  }

  context.logger.warn(
    'The "@angular-devkit/build-angular:browser" builder is deprecated as part of Angular\'s Webpack support deprecation. ' +
      'Use "@angular/build:application" instead. For more information, see https://angular.dev/tools/cli/build-system-migration.',
  );

  const baseOutputPath = path.resolve(context.workspaceRoot, options.outputPath);
  let outputPaths: undefined | Map<string, string>;

  // Check Angular version.
  assertCompatibleAngularVersion(context.workspaceRoot);

  return from(context.getProjectMetadata(projectName)).pipe(
    switchMap(async (projectMetadata) => {
      // Purge old build disk cache.
      await purgeStaleBuildCache(context);

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Run the builder via a properly defined target in angular.json (ng build / ng run project:browser).
  2. If invoking programmatically, ensure the ArchitectContext has target.project set (e.g. architect.scheduleTarget({ project, target, configuration })).
  3. Migrate to the non-deprecated '@angular/build:application' builder, which also has clearer context requirements.
  4. Check angular.json that the target belongs to an existing project and the project key is spelled correctly.

Example fix

// before
architect.scheduleTarget({ target: 'build' }); // no project
// after
architect.scheduleTarget({ project: 'my-app', target: 'build', configuration: 'production' });
Defensive patterns

Strategy: validation

Validate before calling

import type { BuilderContext } from '@angular-devkit/architect';
function assertTarget(context: BuilderContext): string {
  const project = context.target?.project;
  if (!project) throw new Error('Schedule this builder via a named target with a project.');
  return project;
}

Type guard

const hasTarget = (ctx: { target?: { project?: string } | null }): ctx is { target: { project: string } } =>
  typeof ctx.target?.project === 'string' && ctx.target.project.length > 0;

Try / catch

try {
  await scheduleBrowserBuild();
} catch (e) {
  if (String(e.message) === 'The builder requires a target.') {
    // fix scheduling: use architect.scheduleTarget with project + target
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling the browser builder programmatically with a context lacking target info (e.g. context.target is undefined or target.project is empty), invoking the builder directly through the Architect API without scheduling it via a named target in angular.json, or using executeBuilder with a target that has no project set.

Common situations: Custom CLI scripts driving Architect directly; testing the builder with a mock context missing target; running a target definition whose 'project' key was typo'd or omitted; tooling that invokes builders without angular.json targets.

Related errors


AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30). Data as JSON: /api/errors/0b40d607ac811f2d. Report an issue: GitHub.