angular/angular-cli · error · Error

Failed to detect the builder used by the application. Please

Error message

Failed to detect the builder used by the application. Please set builderMode explicitly.

What it means

checkForEsbuild determines whether the application under test uses an esbuild-based builder by looking up the project's build/development target. If the underlying lookup throws exactly 'Project target does not exist.', the builder cannot 'detect' the mode and rethrows this clearer error, advising the user to set `builderMode` explicitly in karma options. Any other error is rethrown as-is.

Source

Thrown at packages/angular_devkit/build_angular/src/builders/karma/index.ts:204

  // Look up the current project's build target using a development configuration.
  const buildTargetSpecifier = `::development`;
  const buildTarget = targetFromTargetString(
    buildTargetSpecifier,
    context.target?.project,
    'build',
  );

  try {
    const developmentBuilderName = await context.getBuilderNameForTarget(buildTarget);

    return isEsbuildBased(developmentBuilderName);
  } catch (e) {
    if (!(e instanceof Error) || e.message !== 'Project target does not exist.') {
      throw e;
    }
    // If we can't find a development builder, we can't use 'detect'.
    throw new Error(
      'Failed to detect the builder used by the application. Please set builderMode explicitly.',
      { cause: e },
    );
  }
}

function isEsbuildBased(
  builderName: string,
): builderName is
  | '@angular/build:application'
  | '@angular-devkit/build-angular:application'
  | '@angular-devkit/build-angular:browser-esbuild' {
  if (
    builderName === '@angular/build:application' ||
    builderName === '@angular-devkit/build-angular:application' ||
    builderName === '@angular-devkit/build-angular:browser-esbuild'
  ) {
    return true;

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Set `builderMode` explicitly in the karma/test target options: `"options": { "builderMode": "esbuild" }` (or "webpack").
  2. Add or restore a build target for the project in angular.json so detection can resolve it.
  3. If relying on detection, ensure the project defines the expected build/development target names.
  4. Check for typos in target names/configurations referenced by detection.

Example fix

// before (angular.json test target options)
{ "karmaConfig": "karma.conf.js" }
// after
{ "karmaConfig": "karma.conf.js", "builderMode": "esbuild" }
Defensive patterns

Strategy: fallback

Validate before calling

const hasBuildTarget =
  (architectProject.targets?.build ?? architectProject.architect?.build) !== undefined;
const builderMode = hasBuildTarget ? undefined : 'esbuild'; // set explicitly when detection impossible

Try / catch

try {
  await ngTest();
} catch (e) {
  if (e.message.includes('Failed to detect the builder used by the application')) {
    console.error('Set "builderMode" in test target options.');
  } else throw e;
}

Prevention

When it happens

Trigger: Running `ng test` where the project has no build (or development-configuration) target to inspect, and karma options do not specify `builderMode`; a project whose angular.json lacks the builder target that detection depends on.

Common situations: Test-only projects or libraries with no build target; renamed/deleted application build target; workspaces migrating between webpack and esbuild builders where detection can't infer the mode.

Related errors


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