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
- 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.
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
- 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.
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
- Specified module '${options.module}' does not exist.\nLooked
- Option "project" is required.
- Module option required when creating a lazy loaded routing m
- No route declaration array was found that corresponds to rou
- More than one module matches. Use the '--skip-import' option
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/6a4246b73edd904f.
Report an issue: GitHub.