angular/angular-cli · error · SchematicsException

No "test" target found for project "${options.project}". A "

Error message

No "test" target found for project "${options.project}". A "test" target is required to generate a Vitest configuration.

What it means

After locating the project, `addVitestConfig` requires the project to have a `test` architect target (`project.targets.get('test')`). If the project defines no `test` target, there is nowhere to attach the Vitest configuration, so the schematic throws this exception. The Vitest config generation is designed to augment an existing unit-test builder setup, not to create the target itself.

Source

Thrown at packages/schematics/angular/config/index.ts:55

      default:
        throw new SchematicsException(`"${options.type}" is an unknown configuration file type.`);
    }
  },
);

export default configSchematic;

function addVitestConfig(options: ConfigOptions): Rule {
  return (tree, context) =>
    updateWorkspace((workspace) => {
      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 Vitest configuration.',
        );
      }

      if (testTarget.builder !== AngularBuilder.BuildUnitTest) {
        throw new SchematicsException(
          `Cannot add a Vitest configuration as builder for "test" target in project does not` +
            ` use "${AngularBuilder.BuildUnitTest}".`,
        );
      }

      testTarget.options ??= {};
      testTarget.options.runnerConfig = true;

      // Check runner option.
      if (testTarget.options.runner === 'karma') {
        context.logger.warn(

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Add a `test` target to the project in angular.json using the unit-test builder, e.g. `"test": { "builder": "@angular/build:unit-test", "options": {} }`.
  2. Regenerate testing support with `ng generate config <project> --type vitest` only after the test target exists.
  3. Verify the correct project was targeted — another project in the workspace may already have the test target.

Example fix

// angular.json before
"my-app": { "architect": { "build": { ... } } }
// after
"my-app": { "architect": {
  "build": { ... },
  "test": { "builder": "@angular/build:unit-test", "options": { "tsConfig": "tsconfig.spec.json" } }
} }
Defensive patterns

Strategy: validation

Validate before calling

const angularJson = JSON.parse(tree.read('angular.json')!.toString('utf8'));
const project = angularJson.projects[options.project];
if (!project?.architect?.test && !project?.targets?.test) {
  throw new Error(`Project "${options.project}" has no "test" target; add @angular/build:unit-test first.`);
}

Type guard

function hasTestTarget(p: any): p is { architect: { test: object } } {
  return !!p && !!(p.architect?.test ?? p.targets?.test);
}

Try / catch

try {
  await runSchematic('config', { project, type: 'vitest' });
} catch (e) {
  if (e instanceof SchematicsException && e.message.includes('No "test" target')) {
    console.error('Add a test target (unit-test builder) before generating a Vitest config.');
  } else throw e;
}

Prevention

When it happens

Trigger: Running `ng generate config <project> --type vitest` against a project whose angular.json entry lacks a `targets`/`architect` `test` entry — e.g. a plain application generated with only build/serve targets, or a library without a test target.

Common situations: Older projects that never had a test target; projects where the test target was manually removed; new libraries created without testing; running the config schematic before adding `@angular/build:unit-test` (or karma) builder to the project.

Related errors


AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30). Data as JSON: /api/errors/1de4b74e9ee180c6. Report an issue: GitHub.