{"record":{"id":"5fac97f0c110a362","repo":"angular/angular-cli","slug":"no-route-declaration-array-was-found-that-correspo","errorCode":null,"errorMessage":"No route declaration array was found that corresponds to router module at line ${line} in ${fileToAdd}","messagePattern":"No route declaration array was found that corresponds to router module at line (.+?) in (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/schematics/angular/utility/ast-utils.ts","lineNumber":637,"sourceCode":"  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      });\n    }\n\n    if (!routesVar) {\n      const { line } = source.getLineAndCharacterOfPosition(routesArg.getStart());\n      throw new Error(\n        `No route declaration array was found that corresponds ` +\n          `to router module at line ${line} in ${fileToAdd}`,\n      );\n    }\n\n    routesArr = findNodes(\n      routesVar,\n      ts.SyntaxKind.ArrayLiteralExpression,\n      1,\n    )[0] as ts.ArrayLiteralExpression;\n  }\n\n  const occurrencesCount = routesArr.elements.length;\n  const text = routesArr.getFullText(source);\n\n  let route: string = routeLiteral;\n  let insertPos = routesArr.elements.pos;\n","sourceCodeStart":619,"sourceCodeEnd":655,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/schematics/angular/utility/ast-utils.ts#L619-L655","documentation":"addRouteDeclarationToModule locates the variable holding the Routes array (the second argument of forRoot/forChild, e.g. `appRoutes`) in the module source. When the RouterModule.forRoot/forChild call's argument does not correspond to any declared array variable in the file, the schematic cannot know where to append the new route and throws this error.","triggerScenarios":"Running `ng generate module --routing` or route-adding schematics against a module where the RouterModule.forRoot(...) / forChild(...) second argument is not a simple identifier referencing a locally declared array — e.g. it is inlined, imported from elsewhere, or the array declaration was removed.","commonSituations":"Hand-edited app.module.ts where `const routes: Routes = [...]` was deleted or renamed; routes defined inline as `RouterModule.forRoot([])`; routes imported from a separate file; code minified or heavily refactored before re-running the schematic.","solutions":["Declare the routes as a named exported/const array in the same file, e.g. `const routes: Routes = [];` and pass it: `RouterModule.forRoot(routes)`.","Ensure the array variable name matches what is passed to forRoot/forChild (no inline literals).","Add the route manually with `@NgModule` imports edited by hand, then re-run generation with --skip-import style options where available."],"exampleFix":"// before\n@NgModule({ imports: [RouterModule.forRoot([])] })\n// after\nconst routes: Routes = [];\n@NgModule({ imports: [RouterModule.forRoot(routes)] })","handlingStrategy":"validation","validationCode":"const src = fs.readFileSync('src/app/app.module.ts', 'utf8');\nif (!/RouterModule\\.for(Root|Child)\\(\\s*[A-Za-z_$][\\w$]*\\s*\\)/.test(src)) {\n  throw new Error('RouterModule call must reference a named routes array in the same file');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always declare routes as a named const array passed to forRoot/forChild, never inline literals.","Keep the routes array declaration in the same module file as the forRoot/forChild call.","Avoid renaming/deleting the routes variable without updating the module."],"tags":["angular","schematics","routing","ast"],"backgroundTag":"missing-routes-array-declaration","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}