angular/angular-cli · error

Need Workflow to support executing schematics as post tasks.

Error message

Need Workflow to support executing schematics as post tasks.

What it means

RunSchematicTask re-enters a workflow to execute the requested schematic as a post task. The engine's workflow reference (context.engine.workflow) is optional; base engines without workflow support leave it undefined and the executor throws instead of silently failing.

Source

Thrown at packages/angular_devkit/schematics/tasks/run-schematic/executor.ts:24

 * found in the LICENSE file at https://angular.dev/license
 */

import { SchematicContext, TaskExecutor } from '../../src';
import { RunSchematicTaskOptions } from './options';

export default function (): TaskExecutor<RunSchematicTaskOptions<{}>> {
  return (options: RunSchematicTaskOptions<{}> | undefined, context: SchematicContext) => {
    if (!options?.name) {
      throw new Error(
        'RunSchematicTask requires an options object with a non-empty name property.',
      );
    }

    const maybeWorkflow = context.engine.workflow;
    const collection = options.collection || context.schematic.collection.description.name;

    if (!maybeWorkflow) {
      throw new Error('Need Workflow to support executing schematics as post tasks.');
    }

    return maybeWorkflow.execute({
      collection: collection,
      schematic: options.name,
      options: options.options,
      // Allow private when calling from the same collection.
      allowPrivate: collection == context.schematic.collection.description.name,
    });
  };
}

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Run schematics through a full Workflow implementation (e.g. BaseWorkflow from @angular-devkit/schematics) and attach it to the engine
  2. Use the standard NodeWorkflow / testing workflow so context.engine.workflow is populated
  3. Avoid RunSchematicTask in engines that lack workflow support; execute follow-up schematics directly instead
  4. Update custom engine hosts to expose a workflow reference

Example fix

// before
const engine = new SchematicEngine(new MyBasicHost()); // no workflow
callSchematic(engine, { postTask: true }); // throws
// after
const workflow = new NodeWorkflow(fsHost, { dryRun: false });
// engine created by the workflow has context.engine.workflow available
Defensive patterns

Strategy: validation

Validate before calling

if (!context.engine.workflow) {
  throw new Error('Engine has no workflow; RunSchematicTask cannot be used.');
}
context.addTask(new RunSchematicTask({ name: 'post-setup' }));

Type guard

function supportsRunSchematic(context: SchematicContext): boolean {
  return !!context.engine.workflow;
}

Try / catch

try {
  context.addTask(new RunSchematicTask(options));
} catch (e) {
  if (/Need Workflow/.test(String(e))) {
    // execute the follow-up schematic directly via the workflow instead
  } else throw e;
}

Prevention

When it happens

Trigger: Scheduling a RunSchematicTask while the engine was constructed without a Workflow-backed host (e.g. plain Engine host, custom test harnesses, older/basic workflow implementations).

Common situations: Custom schematic runners/CLIs built on the engine directly without creating a BaseWorkflow; test harnesses that stub the engine; running schematics programmatically with a minimal setup.

Related errors


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