angular/angular-cli · error · Error

More than one module matches. Use the '--skip-import' option

Error message

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.

What it means

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.

Source

Thrown at packages/schematics/angular/utility/find-module.ts:109

  let foundRoutingModule = false;

  const moduleExtensions: string[] = moduleExt ? [moduleExt] : [MODULE_EXT, MODULE_EXT_LEGACY];
  const routingModuleExtensions: string[] = routingModuleExt
    ? [routingModuleExt]
    : [ROUTING_MODULE_EXT, ROUTING_MODULE_EXT_LEGACY];

  while (dir) {
    const allMatches = dir.subfiles.filter((p) => moduleExtensions.some((m) => p.endsWith(m)));
    const filteredMatches = allMatches.filter(
      (p) => !routingModuleExtensions.some((m) => p.endsWith(m)),
    );

    foundRoutingModule = foundRoutingModule || allMatches.length !== filteredMatches.length;

    if (filteredMatches.length == 1) {
      return join(dir.path, filteredMatches[0]);
    } else if (filteredMatches.length > 1) {
      throw new Error(
        `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.',
      );
    }

    dir = dir.parent;
  }

  const errorMsg = foundRoutingModule
    ? '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.`
    : `Could not find an NgModule. Use the '--skip-import' option to skip importing in NgModule.`;

  throw new Error(errorMsg);
}

/**

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Specify the target module explicitly: `ng g c my-comp -m feature`.
  2. Use `--skip-import` if you intend to wire imports yourself.
  3. Reorganize so only one non-routing NgModule is discoverable per directory.

Example fix

// before
ng g c user/list
// after
ng g c user/list --module=user/user.module
Defensive patterns

Strategy: validation

Validate before calling

const ngModules = glob.sync('src/app/**/*.module.ts').filter(f => !/-routing\.module\.ts$/.test(f));
if (ngModules.filter(f => path.dirname(f) === targetDir).length > 1) {
  console.warn('Multiple non-routing NgModules — pass --module explicitly.');
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30). Data as JSON: /api/errors/49f3442665283db3. Report an issue: GitHub.