angular/angular-cli · error · UnknownTaskDependencyException

Unknown task dependency [ID: ${id.id}].

Error message

Unknown task dependency [ID: ${id.id}].

What it means

Schematics tasks are registered and referenced by opaque TaskId. _mapDependencies resolves a TaskConfiguration's dependencies array by looking each id up in the engine's `_taskIds` map; any id that was never registered (or already completed/cleared) throws UnknownTaskDependencyException. It indicates the scheduler was asked to wait on a task that does not exist in the current engine run.

Source

Thrown at packages/angular_devkit/schematics/src/engine/engine.ts:134

  private _calculatePriority(dependencies: Set<TaskInfo>): number {
    if (dependencies.size === 0) {
      return 0;
    }

    const prio = [...dependencies].reduce((prio, task) => prio + task.priority, 1);

    return prio;
  }

  private _mapDependencies(dependencies?: Array<TaskId>): Set<TaskInfo> {
    if (!dependencies) {
      return new Set();
    }

    const tasks = dependencies.map((dep) => {
      const task = this._taskIds.get(dep);
      if (!task) {
        throw new UnknownTaskDependencyException(dep);
      }

      return task;
    });

    return new Set(tasks);
  }

  schedule<T extends object>(taskConfiguration: TaskConfiguration<T>): TaskId {
    const dependencies = this._mapDependencies(taskConfiguration.dependencies);
    const priority = this._calculatePriority(dependencies);

    const task = {
      id: TaskScheduler._taskIdCounter++,
      priority,
      configuration: taskConfiguration,
      context: this._context,
    };

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Only use TaskId values returned by `context.addTask(...)` within the same engine run that schedules the dependent task
  2. Re-run the full pipeline so all referenced tasks are registered before their dependents are scheduled
  3. If ids cross schematic boundaries, execute in the same engine/context instead of separate engines

Example fix

// before
const id = otherEngine.execute(...); // different engine
context.addTask(new NodePackageInstallTask(), [id]);
// after
const id = context.addTask(new RunSchematicTask('build', {}));
context.addTask(new NodePackageInstallTask(), [id]); // same engine run
Defensive patterns

Strategy: try-catch

Try / catch

import { UnknownTaskDependencyException } from '@angular-devkit/schematics';
try {
  engine.execute(collectionName, options);
} catch (err) {
  if (err instanceof UnknownTaskDependencyException) {
    console.error(`Task ${err.id} is not registered in this engine run; check task id usage.`);
  } else throw err;
}

Prevention

When it happens

Trigger: A schematic declares `options`/task dependencies referencing a task id obtained from a different SchematicEngine/context, or from a previous run, so `_taskIds.get(dep)` returns undefined during task scheduling via `dependencies()`.

Common situations: Caching task ids across engine instances or test setups; sharing task ids between separate `execute()` runs; a host schematic depending on a task id returned by a sub-schematic executed in a different engine.

Related errors


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