{"record":{"id":"6a4246b73edd904f","repo":"angular/angular-cli","slug":"could-not-find-a-non-routing-ngmodule-nmodules-wi","errorCode":null,"errorMessage":"Could not find a non Routing NgModule.\\nModules with suffix '${routingModuleExt}' are strictly reserved for routing.\\nUse the '--skip-import' option to skip importing in NgModule.","messagePattern":"Could not find a non Routing NgModule\\.\\\\nModules with suffix '(.+?)' are strictly reserved for routing\\.\\\\nUse the '--skip-import' option to skip importing in NgModule\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/schematics/angular/utility/find-module.ts","lineNumber":124,"sourceCode":"    if (filteredMatches.length == 1) {\n      return join(dir.path, filteredMatches[0]);\n    } else if (filteredMatches.length > 1) {\n      throw new Error(\n        `More than one module matches. Use the '--skip-import' option to skip importing ` +\n          'the component into the closest module or use the module option to specify a module.',\n      );\n    }\n\n    dir = dir.parent;\n  }\n\n  const errorMsg = foundRoutingModule\n    ? 'Could not find a non Routing NgModule.' +\n      `\\nModules with suffix '${routingModuleExt}' are strictly reserved for routing.` +\n      `\\nUse the '--skip-import' option to skip importing in NgModule.`\n    : `Could not find an NgModule. Use the '--skip-import' option to skip importing in NgModule.`;\n\n  throw new Error(errorMsg);\n}\n\n/**\n * Build a relative path from one file path to another file path.\n */\nexport function buildRelativePath(from: string, to: string): string {\n  from = normalize(from);\n  to = normalize(to);\n\n  // Convert to arrays.\n  const fromParts = from.split('/');\n  const toParts = to.split('/');\n\n  // Remove file names (preserving destination)\n  fromParts.pop();\n  const toFileName = toParts.pop();\n\n  const relativePath = relative(","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/schematics/angular/utility/find-module.ts#L106-L142","documentation":"When findModule finds no eligible NgModule in any ancestor directory, it throws a contextual error: if the only matches were routing modules (*.routing.ts / *-routing.module.ts), it explains that those are reserved for routing; otherwise it says no NgModule was found at all.","triggerScenarios":"Generating a component/directive/pipe outside the scope of any non-routing NgModule — e.g. inside a folder where only a routing module exists, or in a directory tree with no NgModules, without --skip-import.","commonSituations":"Creating files in a standalone-component project (no NgModules); generating into a `*.routing.module.ts`-only directory; generating outside src/app; projects migrated to standalone APIs still running NgModule-based generators.","solutions":["Pass an explicit module: `ng g c x -m path/to/app.module`.","Use `--skip-import` since no module import is needed.","Use `--standalone` for the generated component if the project is standalone.","Move the file into a directory owned by a non-routing NgModule."],"exampleFix":"// before\nng g c pages/settings\n// after\nng g c pages/settings --skip-import","handlingStrategy":"validation","validationCode":"if (!glob.sync('src/app/**/*.module.ts').some(f => !/-routing\\.module\\.ts$/.test(f))) {\n  console.warn('No non-routing NgModule found — use --skip-import or --standalone.');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use --skip-import for standalone-component projects.","Never place the only NgModule in a folder as a routing module.","Set `\"schematics\": { \"@schematics/angular:component\": { \"standalone\": true } }` in angular.json for module-less projects."],"tags":["angular","schematics","cli","ngmodule","routing"],"backgroundTag":"module-not-found","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}