angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

"No module files found" error when trying to generate components

Open kmaida opened this issue 10 years ago • 15 comments

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.

kmaida avatar Oct 31 '16 16:10 kmaida

Same here, running windows 7

martov1 avatar Nov 02 '16 06:11 martov1

Same here:

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

eirikkva avatar Nov 02 '16 09:11 eirikkva

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

filipesilva avatar Nov 03 '16 17:11 filipesilva

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)

bbakov avatar Nov 10 '16 18:11 bbakov

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.

vargalas avatar Nov 11 '16 21:11 vargalas

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

ozplc83 avatar Nov 21 '16 19:11 ozplc83

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 avatar Nov 28 '16 15:11 richardsengers

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

vargalas avatar Nov 28 '16 16:11 vargalas

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?

kmaida avatar Nov 28 '16 18:11 kmaida

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

DamengRandom avatar Jan 26 '17 07:01 DamengRandom

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

phacic avatar Jun 19 '17 19:06 phacic

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?? :\

cturker avatar Jul 11 '17 11:07 cturker

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

velicko018 avatar Jul 15 '17 15:07 velicko018

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

Miltonsms avatar Jul 18 '17 17:07 Miltonsms

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.