angular-cli: "No module files found" error when trying to generate components

Mac OSX 10.11.6 angular-cli: 1.0.0-beta.19-3 Node: 6.9.0

When developing apps created with the CLI, sometimes the ng g / ng generate command fails apparently arbitrarily. It’ll be working fine and then suddenly stop working and throw an error. Sometimes the next time I come back to the project the following day, it will work again.

Example:

ng g component home ng generate directive test …etc.

The only output received whenever this happens is a red error stating:

Error locating module for declaration                                                                                         
        SilentError: No module files found 

I’ve encountered this using CLI versions beta.18 as well as beta.19-3 and on multiple projects.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 15 (1 by maintainers)

Commits related to this issue

Most upvoted comments

You can create your component as follows “ng g c home --module=app.module.ts” This worked for me 😄

After I have tried on my own project,

I think in angular 2, if we create some file name like xxx.module.ts inside the app folder, this error occurs, if we remove this xxx.module.ts file inside src/app folder, we can generate the component files.

I have tried this solution and which works for me

I think it’s because people have moved the app.module.ts from the root of the app. For instance when I moved my app.module.ts to a folder app/modules/ the error pops up.

Rename app.module.shared.ts to app.module.ts and change path in client and server module

angular-cli: 1.0.0-beta.20-4 node: 6.9.1 os: linux x64 Running the command to generate new components gives an error and the components are not created.

example: ng generate component edit-constant

This is just that it comes out after executing the command:

installing component Error locating module for declaration SilentError: No module files found

This seems to be working for me too after updating my projects to move the app module file. Sorry for the pollution of the issue with references! I’m happy to close this issue, unless @Brocco, @filipesilva, you still want to examine making this work with the app.module.ts file NOT in the root?