{"record":{"id":"49f3442665283db3","repo":"angular/angular-cli","slug":"more-than-one-module-matches-use-the-skip-impo","errorCode":null,"errorMessage":"More than one module matches. Use the '--skip-import' option to skip importing the component into the closest module or use the module option to specify a module.","messagePattern":"More than one module matches\\. Use the '--skip-import' option to skip importing the component into the closest module or use the module option to specify a module\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/schematics/angular/utility/find-module.ts","lineNumber":109,"sourceCode":"  let foundRoutingModule = false;\n\n  const moduleExtensions: string[] = moduleExt ? [moduleExt] : [MODULE_EXT, MODULE_EXT_LEGACY];\n  const routingModuleExtensions: string[] = routingModuleExt\n    ? [routingModuleExt]\n    : [ROUTING_MODULE_EXT, ROUTING_MODULE_EXT_LEGACY];\n\n  while (dir) {\n    const allMatches = dir.subfiles.filter((p) => moduleExtensions.some((m) => p.endsWith(m)));\n    const filteredMatches = allMatches.filter(\n      (p) => !routingModuleExtensions.some((m) => p.endsWith(m)),\n    );\n\n    foundRoutingModule = foundRoutingModule || allMatches.length !== filteredMatches.length;\n\n    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/**","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/schematics/angular/utility/find-module.ts#L91-L127","documentation":"findModule walks up parent directories looking for NgModule files; when more than one candidate module (after filtering routing modules) matches in a directory, the schematic cannot decide which one to import the new item into and throws, instructing the user to be explicit.","triggerScenarios":"Running `ng generate component|directive|pipe` in a directory that contains (or whose ancestors contain) two or more non-routing NgModules, without the `--module` flag.","commonSituations":"Projects with feature modules split alongside shared modules in the same folder (e.g. `feature.module.ts` and `shared.module.ts` side by side); multi-module lazy-loaded folders; generated code that duplicated modules.","solutions":["Specify the target module explicitly: `ng g c my-comp -m feature`.","Use `--skip-import` if you intend to wire imports yourself.","Reorganize so only one non-routing NgModule is discoverable per directory."],"exampleFix":"// before\nng g c user/list\n// after\nng g c user/list --module=user/user.module","handlingStrategy":"validation","validationCode":"const ngModules = glob.sync('src/app/**/*.module.ts').filter(f => !/-routing\\.module\\.ts$/.test(f));\nif (ngModules.filter(f => path.dirname(f) === targetDir).length > 1) {\n  console.warn('Multiple non-routing NgModules — pass --module explicitly.');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass --module when a directory may contain more than one NgModule.","Keep one non-routing NgModule per directory.","Standardize generation scripts to include explicit --module flags."],"tags":["angular","schematics","cli","ambiguity"],"backgroundTag":"ambiguous-module-match","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}