angular/angular-cli · error · Error

schematicName cannot be undefined.

Error message

schematicName cannot be undefined.

What it means

runSchematic executes a schematic workflow and requires a schematicName to know which generator to run. Due to the option parsing/types, schematicName can be undefined at runtime, so it throws this defensive error before executing the workflow.

Source

Thrown at packages/angular/cli/src/command-builder/schematics-command-module.ts:343

      return [collectionName, schematicName];
    }

    return [undefined, schematic];
  }

  protected async runSchematic(options: {
    executionOptions: SchematicsExecutionOptions;
    schematicOptions: OtherOptions;
    collectionName: string;
    schematicName: string;
  }): Promise<number> {
    const { logger } = this.context;
    const { schematicOptions, executionOptions, collectionName, schematicName } = options;
    const workflow = await this.getOrCreateWorkflowForExecution(collectionName, executionOptions);

    if (!schematicName) {
      throw new Error('schematicName cannot be undefined.');
    }

    const { unsubscribe, files } = subscribeToWorkflow(workflow, logger);

    try {
      await workflow
        .execute({
          collection: collectionName,
          schematic: schematicName,
          options: schematicOptions,
          logger,
          allowPrivate: this.allowPrivateSchematics,
        })
        .toPromise();

      if (!files.size) {
        logger.info('Nothing to be done.');
      }

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Provide both collection and schematic: 'ng g @schematics/angular:component my-comp'
  2. Check the command syntax: schematic name is required, e.g. 'ng g component' or 'ng g pkg:generator'
  3. Fix any custom scripts that pass an incomplete options object to runSchematic
  4. Run 'ng g --help' to see required arguments

Example fix

// before
ng generate @nguniversal/express-ng
// after
ng generate @nguniversal/express-ng:app
Defensive patterns

Strategy: validation

Validate before calling

function assertSchematicArgs(args: string[]): void {
  if (args.length === 0 || !args[0].includes(':') === false && args.length < 1) {
    throw new Error('Usage: ng generate [collection:]schematic [options]');
  }
}
// simple check: a schematic name is always present
if (!schematicName) throw new Error('schematicName is required');

Try / catch

try {
  await runSchematic(options);
} catch (e) {
  if ((e as Error).message === 'schematicName cannot be undefined.') {
    throw new Error('Provide a schematic name, e.g. ng g @scope/pkg:schematic');
  }
  throw e;
}

Prevention

When it happens

Trigger: Invoking a schematic command (e.g. 'ng generate' with a collection but no schematic name, or an internal call where options.schematicName was not populated), e.g. 'ng g @scope/collection' without ':' schematic part.

Common situations: Typing 'ng generate' with a collection-only argument; custom tooling calling the schematics command module with incomplete options; alias/shell script passing wrong argument order.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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