{"record":{"id":"9441b0c57cf32fb4","repo":"angular/angular-cli","slug":"failed-to-detect-the-builder-used-by-the-applicati","errorCode":null,"errorMessage":"Failed to detect the builder used by the application. Please set builderMode explicitly.","messagePattern":"Failed to detect the builder used by the application\\. Please set builderMode explicitly\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/build_angular/src/builders/karma/index.ts","lineNumber":204,"sourceCode":"\n  // Look up the current project's build target using a development configuration.\n  const buildTargetSpecifier = `::development`;\n  const buildTarget = targetFromTargetString(\n    buildTargetSpecifier,\n    context.target?.project,\n    'build',\n  );\n\n  try {\n    const developmentBuilderName = await context.getBuilderNameForTarget(buildTarget);\n\n    return isEsbuildBased(developmentBuilderName);\n  } catch (e) {\n    if (!(e instanceof Error) || e.message !== 'Project target does not exist.') {\n      throw e;\n    }\n    // If we can't find a development builder, we can't use 'detect'.\n    throw new Error(\n      'Failed to detect the builder used by the application. Please set builderMode explicitly.',\n      { cause: e },\n    );\n  }\n}\n\nfunction isEsbuildBased(\n  builderName: string,\n): builderName is\n  | '@angular/build:application'\n  | '@angular-devkit/build-angular:application'\n  | '@angular-devkit/build-angular:browser-esbuild' {\n  if (\n    builderName === '@angular/build:application' ||\n    builderName === '@angular-devkit/build-angular:application' ||\n    builderName === '@angular-devkit/build-angular:browser-esbuild'\n  ) {\n    return true;","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/build_angular/src/builders/karma/index.ts#L186-L222","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set `builderMode` explicitly in the karma/test target options: `\"options\": { \"builderMode\": \"esbuild\" }` (or \"webpack\").","Add or restore a build target for the project in angular.json so detection can resolve it.","If relying on detection, ensure the project defines the expected build/development target names.","Check for typos in target names/configurations referenced by detection."],"exampleFix":"// before (angular.json test target options)\n{ \"karmaConfig\": \"karma.conf.js\" }\n// after\n{ \"karmaConfig\": \"karma.conf.js\", \"builderMode\": \"esbuild\" }","handlingStrategy":"fallback","validationCode":"const hasBuildTarget =\n  (architectProject.targets?.build ?? architectProject.architect?.build) !== undefined;\nconst builderMode = hasBuildTarget ? undefined : 'esbuild'; // set explicitly when detection impossible","typeGuard":null,"tryCatchPattern":"try {\n  await ngTest();\n} catch (e) {\n  if (e.message.includes('Failed to detect the builder used by the application')) {\n    console.error('Set \"builderMode\" in test target options.');\n  } else throw e;\n}","preventionTips":["Set builderMode explicitly in CI where the build target may be absent.","Keep a build target defined for every testable application project.","Don't rename the build target without updating test options.","Document builderMode in workspace templates to avoid detection issues."],"tags":["karma","angular","detection","config"],"backgroundTag":"builder-mode-undetectable","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}