{"record":{"id":"604fa437106a6a5b","repo":"angular/angular-cli","slug":"the-karma-builder-requires-a-target-to-be-specif","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/browser_builder.ts","lineNumber":53,"sourceCode":"): AsyncIterable<BuilderOutput> {\n  let karmaServer: Server;\n  let isCancelled = false;\n\n  return new ReadableStream({\n    async start(controller) {\n      const [karma, webpackConfig] = await initializeBrowser(\n        options,\n        context,\n        transforms.webpackConfiguration,\n      );\n\n      if (isCancelled) {\n        return;\n      }\n\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 projectMetadata = await context.getProjectMetadata(projectName);\n      const sourceRoot = (projectMetadata.sourceRoot ?? projectMetadata.root ?? '') as string;\n\n      if (!options.main) {\n        webpackConfig.entry ??= {};\n        if (typeof webpackConfig.entry === 'object' && !Array.isArray(webpackConfig.entry)) {\n          if (Array.isArray(webpackConfig.entry['main'])) {\n            webpackConfig.entry['main'].push(getBuiltInMainFile());\n          } else {\n            webpackConfig.entry['main'] = [getBuiltInMainFile()];\n          }\n        }\n      }\n\n      webpackConfig.plugins ??= [];\n      webpackConfig.plugins.push(","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/build_angular/src/builders/karma/browser_builder.ts#L35-L71","documentation":"The karma builder's `start` needs a builder target (project name) from the architect context to look up project metadata such as sourceRoot. When `context.target` is null or has no project, it cannot proceed and throws this error. This typically means the karma builder was invoked programmatically rather than via an `ng test` target in angular.json.","triggerScenarios":"Calling the karma builder's execute/start through the architect API without setting context.target (e.g. `context.scheduleBuilder` misuse or a custom runner that creates a context without a target); invoking the builder outside of a defined test target in angular.json.","commonSituations":"Custom CI scripts scheduling builders directly; test tooling wrapping the builder API without a target; typos in `ng test --project` or running in a workspace where the target definition was removed.","solutions":["Run tests through a defined target: `ng test` or `ng test <project>:test` with a valid angular.json test target.","If scheduling programmatically, provide a target: `context.scheduleTarget({ target: 'test', project: 'my-app' }, options)`.","Verify angular.json contains a test target for the project and the project name is spelled correctly.","Ensure code constructing the builder context sets `target` before invoking the builder."],"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('karma builder must be scheduled with a target (ng test / scheduleTarget).');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runKarma(context, options);\n} catch (e) {\n  if (e.message.includes(\"'karma' builder requires a target\")) {\n    console.error('Invoke via ng test or scheduleTarget with a project.');\n  } else throw e;\n}","preventionTips":["Prefer scheduleTarget over scheduleBuilder for builder invocations.","Keep a valid test target in angular.json for every testable project.","Validate context.target before calling builder APIs in custom tooling.","Avoid `ng test --project` typos; use tab completion or list projects first."],"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"}