angular/angular-cli · error · SchematicsException
Cannot add a karma configuration as builder for "test" targe
Error message
Cannot add a karma configuration as builder for "test" target in project does not use "${AngularBuilder.Karma}", "${AngularBuilder.BuildKarma}", or ${AngularBuilder.BuildUnitTest}. What it means
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.
Source
Thrown at packages/schematics/angular/config/index.ts:135
const project = workspace.projects.get(options.project);
if (!project) {
throw new SchematicsException(`Project name "${options.project}" doesn't not exist.`);
}
const testTarget = project.targets.get('test');
if (!testTarget) {
throw new SchematicsException(
`No "test" target found for project "${options.project}".` +
' A "test" target is required to generate a karma configuration.',
);
}
if (
testTarget.builder !== AngularBuilder.Karma &&
testTarget.builder !== AngularBuilder.BuildKarma &&
testTarget.builder !== AngularBuilder.BuildUnitTest
) {
throw new SchematicsException(
`Cannot add a karma configuration as builder for "test" target in project does not` +
` use "${AngularBuilder.Karma}", "${AngularBuilder.BuildKarma}", or ${AngularBuilder.BuildUnitTest}.`,
);
}
testTarget.options ??= {};
if (testTarget.builder !== AngularBuilder.BuildUnitTest) {
testTarget.options.karmaConfig = path.join(project.root, 'karma.conf.js');
} else {
// `unit-test` uses the `runnerConfig` option which has configuration discovery if enabled
testTarget.options.runnerConfig = true;
let isKarmaRunnerConfigured = false;
// Check runner option
if (testTarget.options.runner) {
if (testTarget.options.runner === 'karma') {
isKarmaRunnerConfigured = true;
} else {View on GitHub (pinned to bb72145f9a)
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.
Example fix
// before
"test": { "builder": "jest-builder:jest", "options": { ... } }
// after
"test": { "builder": "@angular-devkit/build-angular:karma", "options": { ... } } Defensive patterns
Strategy: validation
Validate before calling
const supported = [
'@angular-devkit/build-angular:karma',
'@angular-devkit/build-angular:build-karma',
'@angular/build:unit-test',
];
const b = project.architect?.test?.builder;
if (b && !supported.includes(b)) {
throw new Error(`Test target builder "${b}" is not supported for karma config generation.`);
} Type guard
function supportsKarmaConfig(builder: string | undefined): boolean {
return builder === '@angular-devkit/build-angular:karma'
|| builder === '@angular-devkit/build-angular:build-karma'
|| builder === '@angular/build:unit-test';
} Try / catch
try {
await runSchematic('config', { project, type: 'karma' });
} catch (e) {
if (e instanceof SchematicsException && e.message.includes('Cannot add a karma configuration')) {
console.error('Use a supported karma/unit-test builder on the test target, or skip karma config for this runner.');
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Cannot add a Vitest configuration as builder for "test" targ
- No "test" target found for project "${options.project}". A "
- Option "project" is required.
- Project is not defined in this workspace.
- Targets are not defined for this project.
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/e9fea38a3fedd002.
Report an issue: GitHub.