{"record":{"id":"879c228674d1bcc4","repo":"angular/angular-cli","slug":"module-option-required-when-creating-a-lazy-loaded","errorCode":null,"errorMessage":"Module option required when creating a lazy loaded routing module.","messagePattern":"Module option required when creating a lazy loaded routing module\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/schematics/angular/module/index.ts","lineNumber":93,"sourceCode":"        recorder.insertLeft(change.pos, change.toAdd);\n      }\n    }\n    host.commitUpdate(recorder);\n\n    return host;\n  };\n}\n\nfunction addRouteDeclarationToNgModule(\n  options: ModuleOptions,\n  routingModulePath: string | undefined,\n): Rule {\n  return (host: Tree) => {\n    if (!options.route) {\n      return host;\n    }\n    if (!options.module) {\n      throw new Error('Module option required when creating a lazy loaded routing module.');\n    }\n\n    let path: string;\n    if (routingModulePath) {\n      path = routingModulePath;\n    } else {\n      path = options.module;\n    }\n\n    const sourceText = host.readText(path);\n\n    const addDeclaration = addRouteDeclarationToModule(\n      ts.createSourceFile(path, sourceText, ts.ScriptTarget.Latest, true),\n      path,\n      buildRoute(options, options.module),\n    ) as InsertChange;\n\n    const recorder = host.beginUpdate(path);","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/schematics/angular/module/index.ts#L75-L111","documentation":"The module schematic's route-adding rule requires the `--module` option when `--route` is supplied for a lazy-loaded routing module. Without `--module` it cannot determine which NgModule (or standalone route file) the route declaration should be added to, so it throws.","triggerScenarios":"Calling the module schematic (e.g. `ng generate module foo --route foo --module ???` omitted) with options { route: 'foo', module: undefined } — i.e. `ng g m users --route users` without `--module=app`.","commonSituations":"Developers forget `--module` when generating lazy-loaded feature modules; scripted generation templates omit the module flag; interactive prompt skipped in CI.","solutions":["Re-run with --module, e.g. `ng generate module users --route users --module app.module.ts`.","Pass `--module=app` (the module name resolves to its path) when the routing parent is AppModule.","If the feature is standalone, drop `--route` and use `ng generate module` without lazy-route options, or use `ng g @angular/core:route` style workflows.","In code, set options.module before invoking the Rule."],"exampleFix":"// before\nng g module admin --route admin\n// after\nng g module admin --route admin --module app.module.ts","handlingStrategy":"validation","validationCode":"if (options.route && !options.module) {\n  throw new Error('Pass --module (e.g. --module=app.module.ts) when using --route.');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await generateModule({ route: 'admin', module: 'app.module.ts' });\n} catch (e) {\n  if (e.message.includes('Module option required')) {\n    console.error('Add the --module flag when generating a lazy routed module.');\n  } else throw e;\n}","preventionTips":["Always pair --route with --module when generating lazy modules","Use CLI prompts interactively so missing options are requested","Codify generation flags in npm scripts to keep them consistent","For standalone apps, prefer router file-based or `ng g @angular/core:route` flows"],"tags":["angular","schematics","cli-options","routing"],"backgroundTag":"missing-required-cli-option","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}