angular/angular-cli · error · Error

Could not find a non Routing NgModule.\nModules with suffix

Error message

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.

What it means

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.

Source

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

    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);
}

/**
 * Build a relative path from one file path to another file path.
 */
export function buildRelativePath(from: string, to: string): string {
  from = normalize(from);
  to = normalize(to);

  // Convert to arrays.
  const fromParts = from.split('/');
  const toParts = to.split('/');

  // Remove file names (preserving destination)
  fromParts.pop();
  const toFileName = toParts.pop();

  const relativePath = relative(

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Pass an explicit module: `ng g c x -m path/to/app.module`.
  2. Use `--skip-import` since no module import is needed.
  3. Use `--standalone` for the generated component if the project is standalone.
  4. Move the file into a directory owned by a non-routing NgModule.

Example fix

// before
ng g c pages/settings
// after
ng g c pages/settings --skip-import
Defensive patterns

Strategy: validation

Validate before calling

if (!glob.sync('src/app/**/*.module.ts').some(f => !/-routing\.module\.ts$/.test(f))) {
  console.warn('No non-routing NgModule found — use --skip-import or --standalone.');
}

Prevention

When it happens

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

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

Related errors


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