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 karma configuration.

What it means

`addKarmaConfig` requires the target project to already define a `test` architect target. The karma configuration file (`karma.conf.js`) is generated to be wired into an existing test target, so when `project.targets.get('test')` returns nothing the schematic throws this exception instead of creating a dangling config.

Source

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

      filter((p) => p.endsWith('.browserslistrc.template')),
      // The below is replaced by bazel `npm_package`.
      applyTemplates({ baselineDate: 'BASELINE-DATE-PLACEHOLDER' }),
      move(projectRoot),
    ]),
  );
}

function addKarmaConfig(options: ConfigOptions): Rule {
  return (_, 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 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) {

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Add a `test` target to the project in angular.json (with `@angular/build:unit-test`, `@angular-devkit/build-angular:karma`, or `@angular-devkit/build-angular:build-karma`) before generating the karma config.
  2. Re-run `ng generate config <project> --type karma` after the test target exists.
  3. Confirm you are targeting the intended project; another project may already have a test target.

Example fix

// angular.json before: project has no "test" architect entry
// after
"architect": { "test": { "builder": "@angular-devkit/build-angular:karma", "options": { "main": "src/test.ts" } } }
Defensive patterns

Strategy: validation

Validate before calling

const project = angularJson.projects[options.project];
const testTarget = project?.architect?.test ?? project?.targets?.test;
if (!testTarget) {
  throw new Error(`Project "${options.project}" has no "test" target; cannot generate karma.conf.js.`);
}

Type guard

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

Try / catch

try {
  await runSchematic('config', { project, type: 'karma' });
} catch (e) {
  if (e instanceof SchematicsException && e.message.includes('No "test" target')) {
    console.error('Initialize the test target before generating a karma config.');
  } else throw e;
}

Prevention

When it happens

Trigger: Running `ng generate config <project> --type karma` on a project whose angular.json entry has no `test` target — e.g. a newly created application or library without unit testing set up, or after the test target was manually deleted.

Common situations: Legacy workspaces where testing was never initialized; projects where `ng generate config` is run before any test builder was added; picking the wrong project name so a project without tests is targeted.

Related errors


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