angular/angular-cli · error · InvalidSchematicsNameException
Schematics has invalid name: "${name}".
Error message
Schematics has invalid name: "${name}". What it means
The Schematic constructor validates the schematic's name from its description against /^[-@/_.a-zA-Z0-9]+$/ and throws if it doesn't match. It guarantees schematic names only contain safe identifier characters. A description with an empty or malformed name is rejected at construction time.
Source
Thrown at packages/angular_devkit/schematics/src/engine/schematic.ts:40
} from './interface';
export class InvalidSchematicsNameException extends BaseException {
constructor(name: string) {
super(`Schematics has invalid name: "${name}".`);
}
}
export class SchematicImpl<CollectionT extends object, SchematicT extends object>
implements Schematic<CollectionT, SchematicT>
{
constructor(
private _description: SchematicDescription<CollectionT, SchematicT>,
private _factory: RuleFactory<{}>,
private _collection: Collection<CollectionT, SchematicT>,
private _engine: Engine<CollectionT, SchematicT>,
) {
if (!_description.name.match(/^[-@/_.a-zA-Z0-9]+$/)) {
throw new InvalidSchematicsNameException(_description.name);
}
}
get description(): SchematicDescription<CollectionT, SchematicT> {
return this._description;
}
get collection(): Collection<CollectionT, SchematicT> {
return this._collection;
}
call<OptionT extends object>(
options: OptionT,
host: Observable<Tree>,
parentContext?: Partial<TypedSchematicContext<CollectionT, SchematicT>>,
executionOptions?: Partial<ExecutionOptions>,
): Observable<Tree> {
const context = this._engine.createContext(this, parentContext, executionOptions);
View on GitHub (pinned to bb72145f9a)
Solutions
- Fix the schematic name in the collection description JSON to match the allowed pattern.
- If generating names programmatically, sanitize with name.replace(/[^-@/_.a-zA-Z0-9]/g, '-').
- Verify the collection.json actually being loaded is the one you edited (paths/scope).
Example fix
// before (collection.json)
{"my schematic": {"factory": "./my-schematic"}}
// after
{"my-schematic": {"factory": "./my-schematic"}} Defensive patterns
Strategy: validation
Validate before calling
const NAME_RE = /^[-@/_.a-zA-Z0-9]+$/;
if (!NAME_RE.test(description.name)) {
throw new Error(`Invalid schematic name: ${description.name}`);
} Type guard
function isValidSchematicName(name: unknown): name is string {
return typeof name === 'string' && /^[-@/_.a-zA-Z0-9]+$/.test(name);
} Try / catch
try {
const schematic = collection.createSchematic(name);
} catch (err) {
if (err instanceof InvalidSchematicsNameException) {
console.error(`Fix schematic name: ${err.message}`);
}
} Prevention
- Keep schematic directory names matching the allowed pattern [-@/_.a-zA-Z0-9].
- Sanitize any programmatically generated names.
- Validate collection.json entries in CI with a small schema check.
When it happens
Trigger: Instantiating a Schematic whose SchematicDescription.name contains characters outside [-@/_.a-zA-Z0-9] (spaces, unicode, empty string).
Common situations: Custom collection JSON where 'schematics.<name>.name' was mistyped or auto-generated with whitespace; dynamic generation of schematic descriptions injecting bad names; typos like 'my schematic' with a space.
Related errors
- Unsupported '${strings.classify(selectedTool)}' MCP server c
- "${options.type}" is an unknown configuration file type.
- Selector "${selector}" is invalid.
- Option "project" is required.
- Project is not defined in this workspace.
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/d7eca01c982d893f.
Report an issue: GitHub.