angular/angular-cli · error · CommandModuleError

A collection and schematic is required during execution.

Error message

A collection and schematic is required during execution.

What it means

`ng generate` requires a [collection:]schematic argument (e.g. `component` or `@schematics/angular:component`). run() parses the schematic option with parseSchematicInfo and throws CommandModuleError if either the collection or schematic name cannot be determined.

Source

Thrown at packages/angular/cli/src/commands/generate/cli.ts:112

            schematic: `${collectionName}:${schematicName}`,
          } as ArgumentsCamelCase<
            SchematicsCommandArgs & {
              schematic: string;
            }
          >),
      });
    }

    return localYargs.demandCommand(1, demandCommandFailureMessage);
  }

  async run(options: Options<GenerateCommandArgs> & OtherOptions): Promise<number | void> {
    const { dryRun, schematic, defaults, force, interactive, ...schematicOptions } = options;

    const [collectionName, schematicName] = this.parseSchematicInfo(schematic);

    if (!collectionName || !schematicName) {
      throw new CommandModuleError('A collection and schematic is required during execution.');
    }

    return this.runSchematic({
      collectionName,
      schematicName,
      schematicOptions,
      executionOptions: {
        dryRun,
        defaults,
        force,
        interactive,
      },
    });
  }

  private async getCollectionNames(): Promise<string[]> {
    const [collectionName] = this.parseSchematicInfo(
      // positional = [generate, component] or [generate]

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Specify the schematic: `ng generate component my-comp` or `ng generate @schematics/angular:component my-comp`
  2. If scripting, guard the variable: `[ -n "$SCHEMATIC" ] && ng generate "$SCHEMATIC"`
  3. Check angular.json `cli.defaultCollection` / `schematics` section if bare names aren't resolving
  4. Run `ng generate --help` to see accepted syntax

Example fix

// before
ng generate
// after
ng generate component my-component
Defensive patterns

Strategy: validation

Validate before calling

const schematicArg = options.schematic ?? '';
const [collectionName, schematicName] = schematicArg.includes(':')
  ? schematicArg.split(':')
  : [undefined, schematicArg];
if (!schematicName || (schematicArg.includes(':') && !collectionName)) {
  throw new Error('A collection and schematic is required: ng generate [collection:]schematic');
}

Type guard

function isSchematicArg(s: string | undefined | null): s is string {
  return typeof s === 'string' && s.trim().length > 0 && s !== ':' && !s.startsWith(':');
}

Try / catch

try {
  await generateCommand.run({ schematic: arg, ...rest });
} catch (e) {
  if (e instanceof CommandModuleError && e.message.includes('collection and schematic is required')) {
    logger.error('Usage: ng generate <schematic> [name] — e.g. ng generate component header');
  } else { throw e; }
}

Prevention

When it happens

Trigger: Running `ng generate` with no schematic name, or a value that parseSchematicInfo cannot split into collection+schematic (e.g. empty string, a bare ':' with no parts). With no collection prefix it falls back to the default collection, so failures come from a truly empty/absent identifier.

Common situations: Typing `ng g` and forgetting the blueprint; shell scripts where the schematic variable is empty; misreading syntax like `ng generate my-file.ts`; running in projects where the default collection is unset so a bare schematic name can't be resolved to a collection.

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/bd1baa2ca509d5ba. Report an issue: GitHub.