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
- Specify the schematic: `ng generate component my-comp` or `ng generate @schematics/angular:component my-comp`
- If scripting, guard the variable: `[ -n "$SCHEMATIC" ] && ng generate "$SCHEMATIC"`
- Check angular.json `cli.defaultCollection` / `schematics` section if bare names aren't resolving
- 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
- Always pass a schematic name after `ng generate`
- In scripts, assert the schematic variable is non-empty before invoking
- Use fully-qualified form (collection:schematic) when default collection is uncertain
- Verify cli.defaultCollection in angular.json for bare schematic names
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
- schematicName cannot be undefined.
- The "not" keyword is not supported in JSON Schema.
- Could not find (/.angular.json)
- Unknown schematics built-in module '${id}' requested from sc
- Invalid Path.
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/bd1baa2ca509d5ba.
Report an issue: GitHub.