{"record":{"id":"05b665d08916b1cd","repo":"angular/angular-cli","slug":"the-router-module-method-doesn-t-have-arguments-at","errorCode":null,"errorMessage":"The router module method doesn't have arguments at line ${line} in ${fileToAdd}","messagePattern":"The router module method doesn't have arguments at line (.+?) in (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/schematics/angular/utility/ast-utils.ts","lineNumber":614,"sourceCode":"/**\n * Adds a new route declaration to a router module (i.e. has a RouterModule declaration)\n */\nexport function addRouteDeclarationToModule(\n  source: ts.SourceFile,\n  fileToAdd: string,\n  routeLiteral: string,\n): Change {\n  const routerModuleExpr = getRouterModuleDeclaration(source);\n  if (!routerModuleExpr) {\n    throw new Error(\n      `Couldn't find a route declaration in ${fileToAdd}.\\n` +\n        `Use the '--module' option to specify a different routing module.`,\n    );\n  }\n  const scopeConfigMethodArgs = (routerModuleExpr as ts.CallExpression).arguments;\n  if (!scopeConfigMethodArgs.length) {\n    const { line } = source.getLineAndCharacterOfPosition(routerModuleExpr.getStart());\n    throw new Error(\n      `The router module method doesn't have arguments ` + `at line ${line} in ${fileToAdd}`,\n    );\n  }\n\n  let routesArr: ts.ArrayLiteralExpression | undefined;\n  const routesArg = scopeConfigMethodArgs[0];\n\n  // Check if the route declarations array is\n  // an inlined argument of RouterModule or a standalone variable\n  if (ts.isArrayLiteralExpression(routesArg)) {\n    routesArr = routesArg;\n  } else {\n    const routesVarName = routesArg.getText();\n    let routesVar;\n    if (routesArg.kind === ts.SyntaxKind.Identifier) {\n      routesVar = source.statements.filter(ts.isVariableStatement).find((v) => {\n        return v.declarationList.declarations[0].name.getText() === routesVarName;\n      });","sourceCodeStart":596,"sourceCodeEnd":632,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/schematics/angular/utility/ast-utils.ts#L596-L632","documentation":"After finding the RouterModule declaration, the schematic reads its call arguments (the first should be the routes array). If the RouterModule call expression has zero arguments (e.g. bare `RouterModule.forRoot()` or a non-call reference), there is nowhere to insert the route and it throws, reporting the line number for debugging.","triggerScenarios":"RouterModule declared as `RouterModule.forRoot()` / `forChild()` with no arguments, or `RouterModule` referenced without a call expression so `.arguments` is empty; running route-add schematics against such a module file.","commonSituations":"Placeholder empty forRoot() calls created manually; route config moved to a separate file leaving an empty forRoot(); copy-pasted module skeletons without the routes array.","solutions":["Add an empty routes array to the call: change RouterModule.forRoot() to RouterModule.forRoot([]), then re-run the schematic.","Extract the routes to a constant (e.g. const routes: Routes = []) and pass it: RouterModule.forRoot(routes).","Point --module at the module whose RouterModule call actually receives the routes array.","Move route registration to provideRouter(routes) for standalone apps instead of the empty NgModule call.","null"],"exampleFix":"// before\nimports: [RouterModule.forRoot()]\n// after\nimports: [RouterModule.forRoot([])]","handlingStrategy":"validation","validationCode":"const src = ts.createSourceFile(file, fs.readFileSync(file, 'utf8'), ts.ScriptTarget.Latest, true);\nconst rm = src.statements.find(s => s.getText().includes('RouterModule.forRoot')) as ts.CallExpression | undefined;\nif (!rm || (rm.arguments?.length ?? 0) === 0) {\n  console.warn(`RouterModule call in ${file} has no arguments; add a routes array first.`);\n}","typeGuard":"function hasRoutesArg(n: ts.Node): n is ts.CallExpression & { arguments: [ts.Expression, ...ts.Expression[]] } {\n  return ts.isCallExpression(n) && n.arguments.length > 0;\n}","tryCatchPattern":"try {\n  await generateRouteSchematic();\n} catch (e) {\n  if (String(e?.message).includes(\"doesn't have arguments\")) {\n    console.error('Change RouterModule.forRoot() to RouterModule.forRoot([]) and re-run.');\n  }\n  throw e;\n}","preventionTips":["Never leave forRoot()/forChild() with zero arguments; use an empty array placeholder.","Keep the routes array as a named constant for clarity and easy schematic insertion.","Point --module at the module whose router call receives the routes array.","Prefer provideRouter(routes) in standalone apps to avoid NgModule router pitfalls."],"tags":["angular","router","schematics","ast","module"],"backgroundTag":"router-module-call-no-arguments","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}