{"record":{"id":"e9fea38a3fedd002","repo":"angular/angular-cli","slug":"cannot-add-a-karma-configuration-as-builder-for-t","errorCode":null,"errorMessage":"Cannot add a karma configuration as builder for \"test\" target in project does not use \"${AngularBuilder.Karma}\", \"${AngularBuilder.BuildKarma}\", or ${AngularBuilder.BuildUnitTest}.","messagePattern":"Cannot add a karma configuration as builder for \"test\" target in project does not use \"(.+?)\", \"(.+?)\", or (.+?)\\.","errorType":"exception","errorClass":"SchematicsException","httpStatus":null,"severity":"error","filePath":"packages/schematics/angular/config/index.ts","lineNumber":135,"sourceCode":"      const project = workspace.projects.get(options.project);\n      if (!project) {\n        throw new SchematicsException(`Project name \"${options.project}\" doesn't not exist.`);\n      }\n\n      const testTarget = project.targets.get('test');\n      if (!testTarget) {\n        throw new SchematicsException(\n          `No \"test\" target found for project \"${options.project}\".` +\n            ' A \"test\" target is required to generate a karma configuration.',\n        );\n      }\n\n      if (\n        testTarget.builder !== AngularBuilder.Karma &&\n        testTarget.builder !== AngularBuilder.BuildKarma &&\n        testTarget.builder !== AngularBuilder.BuildUnitTest\n      ) {\n        throw new SchematicsException(\n          `Cannot add a karma configuration as builder for \"test\" target in project does not` +\n            ` use \"${AngularBuilder.Karma}\", \"${AngularBuilder.BuildKarma}\", or ${AngularBuilder.BuildUnitTest}.`,\n        );\n      }\n\n      testTarget.options ??= {};\n      if (testTarget.builder !== AngularBuilder.BuildUnitTest) {\n        testTarget.options.karmaConfig = path.join(project.root, 'karma.conf.js');\n      } else {\n        // `unit-test` uses the `runnerConfig` option which has configuration discovery if enabled\n        testTarget.options.runnerConfig = true;\n\n        let isKarmaRunnerConfigured = false;\n        // Check runner option\n        if (testTarget.options.runner) {\n          if (testTarget.options.runner === 'karma') {\n            isKarmaRunnerConfigured = true;\n          } else {","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/schematics/angular/config/index.ts#L117-L153","documentation":"The karma configuration generator only supports test targets built with one of three builders: `@angular-devkit/build-angular:karma` (`AngularBuilder.Karma`), `@angular-devkit/build-angular:build-karma` (`AngularBuilder.BuildKarma`), or `@angular/build:unit-test` (`AngularBuilder.BuildUnitTest`). If the `test` target uses any other builder, the schematic throws this exception because the generated `karma.conf.js` would not be recognized by the builder.","triggerScenarios":"Running `ng generate config <project> --type karma` when the project's `test` target builder is something else entirely — e.g. a custom/third-party test builder, jest builder, or a mistyped builder string in angular.json.","commonSituations":"Workspaces using non-Karma test runners (Jest/Web Test Runner) whose test targets point at community builders; users attempting to attach a karma.conf.js to a vitest-runner-only unit-test target where the CLI then warns, or to a custom builder; partially migrated workspaces.","solutions":["Switch the test target builder in angular.json to `@angular-devkit/build-angular:karma` or `@angular-devkit/build-angular:build-karma` (or `@angular/build:unit-test`) and re-run the schematic.","If you are using a non-Angular test runner (e.g. Jest), do not generate a karma config; configure that runner's own config file instead.","Verify the builder string in angular.json is not mistyped or referencing a builder that is not installed."],"exampleFix":"// before\n\"test\": { \"builder\": \"jest-builder:jest\", \"options\": { ... } }\n// after\n\"test\": { \"builder\": \"@angular-devkit/build-angular:karma\", \"options\": { ... } }","handlingStrategy":"validation","validationCode":"const supported = [\n  '@angular-devkit/build-angular:karma',\n  '@angular-devkit/build-angular:build-karma',\n  '@angular/build:unit-test',\n];\nconst b = project.architect?.test?.builder;\nif (b && !supported.includes(b)) {\n  throw new Error(`Test target builder \"${b}\" is not supported for karma config generation.`);\n}","typeGuard":"function supportsKarmaConfig(builder: string | undefined): boolean {\n  return builder === '@angular-devkit/build-angular:karma'\n    || builder === '@angular-devkit/build-angular:build-karma'\n    || builder === '@angular/build:unit-test';\n}","tryCatchPattern":"try {\n  await runSchematic('config', { project, type: 'karma' });\n} catch (e) {\n  if (e instanceof SchematicsException && e.message.includes('Cannot add a karma configuration')) {\n    console.error('Use a supported karma/unit-test builder on the test target, or skip karma config for this runner.');\n  } else throw e;\n}","preventionTips":["Only use karma config generation with the three supported builders.","For Jest or other runners, manage their config files outside Angular schematics.","Keep builder strings in angular.json exact and the corresponding packages installed."],"tags":["angular","schematics","builder-mismatch","karma"],"backgroundTag":"builder-version-mismatch","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}