@@ -28,7 +28,7 @@ export function findModuleFromOptions(host: Tree, options: ModuleOptions): Path
28
28
29
29
if ( ! options . module ) {
30
30
const pathToCheck = ( options . path || '' )
31
- + ( options . flat ? '' : '/' + strings . dasherize ( options . name ) ) ;
31
+ + ( options . flat ? '' : '/' + strings . dasherize ( options . name ) ) ;
32
32
33
33
return normalize ( findModule ( host , pathToCheck ) ) ;
34
34
} else {
@@ -59,21 +59,30 @@ export function findModule(host: Tree, generateDir: string): Path {
59
59
const moduleRe = / \. m o d u l e \. t s $ / ;
60
60
const routingModuleRe = / - r o u t i n g \. m o d u l e \. t s / ;
61
61
62
+ let foundRoutingModule = false ;
63
+
62
64
while ( dir ) {
63
- const matches = dir . subfiles . filter ( p => moduleRe . test ( p ) && ! routingModuleRe . test ( p ) ) ;
65
+ const allMatches = dir . subfiles . filter ( p => moduleRe . test ( p ) ) ;
66
+ const filteredMatches = allMatches . filter ( p => ! routingModuleRe . test ( p ) ) ;
67
+
68
+ foundRoutingModule = foundRoutingModule || allMatches . length !== filteredMatches . length ;
64
69
65
- if ( matches . length == 1 ) {
66
- return join ( dir . path , matches [ 0 ] ) ;
67
- } else if ( matches . length > 1 ) {
70
+ if ( filteredMatches . length == 1 ) {
71
+ return join ( dir . path , filteredMatches [ 0 ] ) ;
72
+ } else if ( filteredMatches . length > 1 ) {
68
73
throw new Error ( 'More than one module matches. Use skip-import option to skip importing '
69
74
+ 'the component into the closest module.' ) ;
70
75
}
71
76
72
77
dir = dir . parent ;
73
78
}
74
79
75
- throw new Error ( 'Could not find an NgModule. Use the skip-import '
76
- + 'option to skip importing in NgModule.' ) ;
80
+ const errorMsg = foundRoutingModule ? 'Could not find a non Routing NgModule.'
81
+ + '\nModules with suffix \'-routing.module\' are strictly reserved for routing.'
82
+ + '\nUse the skip-import option to skip importing in NgModule.'
83
+ : 'Could not find an NgModule. Use the skip-import option to skip importing in NgModule.' ;
84
+
85
+ throw new Error ( errorMsg ) ;
77
86
}
78
87
79
88
/**
0 commit comments