Installing component - Error locating module for declaration SilentError: Multiple module files found:
OS?
Mac OSX (Sierra?)
Versions.
angular-cli: 1.0.0-beta.26 node: 6.8.0 os: darwin x64 @angular/common: 2.4.5 @angular/compiler: 2.4.5 @angular/core: 2.4.5 @angular/forms: 2.4.5 @angular/http: 2.4.5 @angular/platform-browser: 2.4.5 @angular/platform-browser-dynamic: 2.4.5 @angular/router: 3.4.5 @angular/compiler-cli: 2.4.5
The log given by the failure.
Error locating module for declaration SilentError: Multiple module files found:
Thanks
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.
@Dameng0803 thanks, this solve the problem
Thanks. this solved my problem
so were not allowed to use the module naming pattern?
I, too, would like the ability to stray from the default module naming convention. Can we get an option to specify which module the newly generated component should be added to?
You do not need to rename any files..
Note that Angular's naming convention is to use <name>-routing.module.ts. This will not raise a conflict in the generator. However if you have other modules (> than 2) and following a different naming pattern; keep reading...
You can explicitly name the module you want to use with -m flag when calling the generator. Try something like this ng g component <path>/<component-name> -m <path>/<module-to-use>.
An example: ng g component posts/votes -m posts/posts.router.module.ts. Note that the path must be explicit
Also the current behavior of throwing an error is temporary within the Angular/CLI, ideally this could provide an option to choose a module from a list or automatically choose the proper module based on Angular's module naming pattern convention.
TIP: I also suggest that you use flag --skip-import because you probably don't want the module automatically inserted into your router's declarations.
Full command example:
ng g component <path>/<component-name> -m <path>/<module-to-use> --skip-import
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
Ya , please rename a file with naming conventions XXX.module.ts to XXX-module.ts .i have tried this and i found the solution
For anyone facing this issue, best way to handle is adding this at the end of the command: --module app.module.ts
Error : [ Error: More than one module matches. Use skip-import option to skip importing the component into the closest module. More than one module matches. Use skip-import option to skip importing the component into the closest module]
This is solved by using ng g component
But I want modules to import in the directives or declarations and other than what fabbballin has suggested, is there any other way?
Hi @RakeshDeshpande ,
Hope this isn't too late.
Use --module=app at the end of your ng g component (name) command. This should import everything into your app.module.ts
Hope that helps.
Edit: same as AlQuraian's answer above.
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.