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

Created on 31 Oct 2016  路  15Comments  路  Source: angular/angular-cli

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.

2 (required) bufix

Most helpful comment

You can create your component as follows "ng g c home --module=app.module.ts" This worked for me :D

All 15 comments

Same here, running windows 7

Same here:

Windows 10
angular-cli: 1.0.0-beta.19-3
Node 6.6.0

I've never seen it myself but the sporadic nature of it might indicate a race condition. @Brocco can you have a look?

I have almost the same issue:

Error locating module for declaration
SilentError: Multiple module files found:

May be the reason for that is changing some of the project files when adding router. (app.module.ts)

I have the same issue on osx.
If I try to create a component in the project root, I have the same error. If I use the same command in the directory where my project's module definition ts file is located, the cli generates the component. Though the location is relative to the module def file.

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

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.

@richardsengers I confirm, it was the problem in my case. When I moved it to the root of the app, it worked fine.

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?

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

In my case i happen to have another .angular-cli.json file in my src folder. Removing it solved the problem

angular 4.1.1
angular-cli 1.0.1

Hi everyone;
In my case i use yeoman aspcore generator. And app.module.ts is different. Later installations of .core seem to split the module into 3 files. client, server and shared.
if i try to install a new component "ng g component xForm" i take "specified module not found" error
Any idea?? :\

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

You can create your component as follows "ng g c home --module=app.module.ts" This worked for me :D

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings