ng generate component in subdirectory

Because there are 2 modules (app.module.ts, shared.module.ts) found the CLI does not know which module to declare your component in. To get around this you have to tell the CLI which module you wish to declare your component in with the module option

ng generate component pages/about --module=app.module
// or
ng generate component pages/about --module=shared.module

To create a component as part of any new module you could also do :

cd newModule to change directory into the newModule folder

ng g c newComponent to create a component as a child of the module.

This worked out for me. I was getting same error as you received.


In general, there is need to generate component in a particular path or not more than one parent module like the above case.

$> ng g component path/component-name  
  <enter> 

No need of src/app/path/component-name ->path, if it is an Angular app. If you mention src/app, then this error occurs.

"Error: More than one module matches. Use skip-import "