{"record":{"id":"77f8db1af978e0af","repo":"angular/angular-cli","slug":"cannot-add-a-vitest-configuration-as-builder-for","errorCode":null,"errorMessage":"Cannot add a Vitest configuration as builder for \"test\" target in project does not use \"${AngularBuilder.BuildUnitTest}\".","messagePattern":"Cannot add a Vitest configuration as builder for \"test\" target in project does not use \"(.+?)\"\\.","errorType":"exception","errorClass":"SchematicsException","httpStatus":null,"severity":"error","filePath":"packages/schematics/angular/config/index.ts","lineNumber":62,"sourceCode":"\nfunction addVitestConfig(options: ConfigOptions): Rule {\n  return (tree, context) =>\n    updateWorkspace((workspace) => {\n      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 Vitest configuration.',\n        );\n      }\n\n      if (testTarget.builder !== AngularBuilder.BuildUnitTest) {\n        throw new SchematicsException(\n          `Cannot add a Vitest configuration as builder for \"test\" target in project does not` +\n            ` use \"${AngularBuilder.BuildUnitTest}\".`,\n        );\n      }\n\n      testTarget.options ??= {};\n      testTarget.options.runnerConfig = true;\n\n      // Check runner option.\n      if (testTarget.options.runner === 'karma') {\n        context.logger.warn(\n          `The \"test\" target is configured to use the \"karma\" runner in the main options.` +\n            ' The generated \"vitest-base.config.ts\" file may not be used.',\n        );\n      }\n\n      for (const [name, config] of Object.entries(testTarget.configurations ?? {})) {\n        if (","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/schematics/angular/config/index.ts#L44-L80","documentation":"Even when a `test` target exists, `addVitestConfig` only supports projects whose test target uses the `@angular/build:unit-test` builder (`AngularBuilder.BuildUnitTest`). If the target uses any other builder (e.g. `@angular-devkit/build-angular:karma`), the schematic refuses to add a Vitest configuration because the generated `vitest-base.config.ts` would not be consumed. The grammatically garbled message means: the test target's builder must be the unit-test builder.","triggerScenarios":"Running `ng generate config <project> --type vitest` when the project's `test` target builder is `@angular-devkit/build-angular:karma` or any builder other than `@angular/build:unit-test`.","commonSituations":"Projects migrated from Karma but still on the legacy karma builder; workspaces mixing old and new builder versions; users who upgraded Angular CLI partially so the new unit-test builder is unavailable; manually authored test targets pointing at a different builder.","solutions":["Change the test target builder in angular.json to `@angular/build:unit-test`, then re-run `ng generate config <project> --type vitest`.","Run the Angular CLI migration to the application builder / unit-test builder (`ng update @angular/cli`) if you are on an older workspace.","If you intend to stay on Karma, generate a karma configuration instead (`--type karma`) rather than a Vitest one."],"exampleFix":"// angular.json before\n\"test\": { \"builder\": \"@angular-devkit/build-angular:karma\", \"options\": { ... } }\n// after\n\"test\": { \"builder\": \"@angular/build:unit-test\", \"options\": { ... } }","handlingStrategy":"validation","validationCode":"const testTarget = project.architect?.test;\nif (testTarget && testTarget.builder !== '@angular/build:unit-test') {\n  throw new Error(`Test target builder is \"${testTarget.builder}\"; Vitest config requires \"@angular/build:unit-test\".`);\n}","typeGuard":"function usesUnitTestBuilder(t: { builder?: string } | undefined): boolean {\n  return t?.builder === '@angular/build:unit-test';\n}","tryCatchPattern":"try {\n  await runSchematic('config', { project, type: 'vitest' });\n} catch (e) {\n  if (e instanceof SchematicsException && e.message.includes('Cannot add a Vitest configuration')) {\n    console.error('Switch the test target builder to @angular/build:unit-test first.');\n  } else throw e;\n}","preventionTips":["Complete `ng update @angular/cli` migrations before generating Vitest configs.","Keep the test target on `@angular/build:unit-test` in all workspace projects.","Never point the test target at the legacy karma builder if you plan to use Vitest."],"tags":["angular","schematics","builder-mismatch","vitest"],"backgroundTag":"builder-version-mismatch","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}