{"record":{"id":"bd1baa2ca509d5ba","repo":"angular/angular-cli","slug":"a-collection-and-schematic-is-required-during-exec","errorCode":null,"errorMessage":"A collection and schematic is required during execution.","messagePattern":"A collection and schematic is required during execution\\.","errorType":"exception","errorClass":"CommandModuleError","httpStatus":null,"severity":"error","filePath":"packages/angular/cli/src/commands/generate/cli.ts","lineNumber":112,"sourceCode":"            schematic: `${collectionName}:${schematicName}`,\n          } as ArgumentsCamelCase<\n            SchematicsCommandArgs & {\n              schematic: string;\n            }\n          >),\n      });\n    }\n\n    return localYargs.demandCommand(1, demandCommandFailureMessage);\n  }\n\n  async run(options: Options<GenerateCommandArgs> & OtherOptions): Promise<number | void> {\n    const { dryRun, schematic, defaults, force, interactive, ...schematicOptions } = options;\n\n    const [collectionName, schematicName] = this.parseSchematicInfo(schematic);\n\n    if (!collectionName || !schematicName) {\n      throw new CommandModuleError('A collection and schematic is required during execution.');\n    }\n\n    return this.runSchematic({\n      collectionName,\n      schematicName,\n      schematicOptions,\n      executionOptions: {\n        dryRun,\n        defaults,\n        force,\n        interactive,\n      },\n    });\n  }\n\n  private async getCollectionNames(): Promise<string[]> {\n    const [collectionName] = this.parseSchematicInfo(\n      // positional = [generate, component] or [generate]","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular/cli/src/commands/generate/cli.ts#L94-L130","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nng generate\n// after\nng generate component my-component","handlingStrategy":"validation","validationCode":"const schematicArg = options.schematic ?? '';\nconst [collectionName, schematicName] = schematicArg.includes(':')\n  ? schematicArg.split(':')\n  : [undefined, schematicArg];\nif (!schematicName || (schematicArg.includes(':') && !collectionName)) {\n  throw new Error('A collection and schematic is required: ng generate [collection:]schematic');\n}","typeGuard":"function isSchematicArg(s: string | undefined | null): s is string {\n  return typeof s === 'string' && s.trim().length > 0 && s !== ':' && !s.startsWith(':');\n}","tryCatchPattern":"try {\n  await generateCommand.run({ schematic: arg, ...rest });\n} catch (e) {\n  if (e instanceof CommandModuleError && e.message.includes('collection and schematic is required')) {\n    logger.error('Usage: ng generate <schematic> [name] — e.g. ng generate component header');\n  } else { throw e; }\n}","preventionTips":["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"],"tags":["angular-cli","generate","schematics","cli-arguments"],"backgroundTag":"missing-required-argument","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}