{"record":{"id":"70d8a6584cc9c259","repo":"angular/angular-cli","slug":"the-karma-builder-requires-a-target-to-be-specif-70d8a6","errorCode":null,"errorMessage":"The 'karma' builder requires a target to be specified.","messagePattern":"The 'karma' builder requires a target to be specified\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/build_angular/src/builders/karma/index.ts","lineNumber":92,"sourceCode":"    const { execute } = await import('./browser_builder');\n\n    yield* execute(options, context, karmaOptions, transforms);\n  }\n}\n\nfunction getBaseKarmaOptions(\n  options: KarmaBuilderOptions,\n  context: BuilderContext,\n): KarmaConfigOptions {\n  let singleRun: boolean | undefined;\n  if (options.watch !== undefined) {\n    singleRun = !options.watch;\n  }\n\n  // Determine project name from builder context target\n  const projectName = context.target?.project;\n  if (!projectName) {\n    throw new Error(`The 'karma' builder requires a target to be specified.`);\n  }\n\n  const karmaOptions: KarmaConfigOptions = options.karmaConfig\n    ? {}\n    : getBuiltInKarmaConfig(context.workspaceRoot, projectName);\n\n  karmaOptions.singleRun = singleRun;\n\n  // Workaround https://github.com/angular/angular-cli/issues/28271, by clearing context by default\n  // for single run executions. Not clearing context for multi-run (watched) builds allows the\n  // Jasmine Spec Runner to be visible in the browser after test execution.\n  karmaOptions.client ??= {};\n  karmaOptions.client.clearContext ??= singleRun ?? false; // `singleRun` defaults to `false` per Karma docs.\n\n  // Convert browsers from a string to an array\n  if (typeof options.browsers === 'string' && options.browsers) {\n    karmaOptions.browsers = options.browsers.split(',');\n  } else if (options.browsers === false) {","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/build_angular/src/builders/karma/index.ts#L74-L110","documentation":"getBaseKarmaOptions (invoked from karmaOptions) derives the project name from the builder context's target to build the default karma configuration. Without a target project, it cannot name the browser instance or resolve project settings, so it throws. Like error 153, this indicates the karma builder was invoked without an architect target.","triggerScenarios":"Invoking the karma builder programmatically with a context whose `target` is undefined/null; custom tooling that calls karmaOptions/getBaseKarmaOptions directly without a target; running a scheduled builder without a project.","commonSituations":"Custom test runners scheduling builders via `scheduleBuilder` instead of `scheduleTarget`; CI harnesses constructing Architect contexts manually; workspaces where angular.json test targets were deleted.","solutions":["Run via `ng test` (or `ng test <project>:test`) so a target is present in the context.","When scheduling programmatically use scheduleTarget with a valid project and target name.","If calling karmaOptions/getBaseKarmaOptions yourself, construct a context with target: { project: '<name>', target: 'test' }.","Restore or define a test target for the project in angular.json."],"exampleFix":"// before\nawait context.scheduleBuilder('@angular-devkit/build-angular:karma', options);\n// after\nawait context.scheduleTarget({ target: 'test', project: 'my-app' }, options);","handlingStrategy":"validation","validationCode":"if (!context.target?.project) {\n  throw new Error('Provide a target project: ng test or scheduleTarget({ project, target: \"test\" }).');\n}","typeGuard":null,"tryCatchPattern":"try {\n  const opts = karmaOptions(context, options);\n} catch (e) {\n  if (e.message.includes(\"'karma' builder requires a target\")) {\n    console.error('Bind a target before computing karma options.');\n  } else throw e;\n}","preventionTips":["Run tests through defined angular.json targets.","Use scheduleTarget programmatically.","Check target presence before invoking karmaOptions in wrappers.","Don't delete test targets when refactoring angular.json."],"tags":["karma","angular","missing-target","config"],"backgroundTag":"missing-builder-target","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}