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

Installing component - Error locating module for declaration SilentError: Multiple module files found:

Open miff opened this issue 9 years ago • 12 comments

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

miff avatar Jan 26 '17 00:01 miff

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

@Dameng0803 thanks, this solve the problem

miff avatar Jan 26 '17 08:01 miff

Thanks. this solved my problem

rajaishtiaq6 avatar Mar 27 '17 18:03 rajaishtiaq6

so were not allowed to use the module naming pattern?

randallmeeker avatar Apr 27 '17 17:04 randallmeeker

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?

IRCraziestTaxi avatar May 09 '17 14:05 IRCraziestTaxi

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

@angular/cli docs

fabioaanthony avatar May 23 '17 15:05 fabioaanthony

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

Ya , please rename a file with naming conventions XXX.module.ts to XXX-module.ts .i have tried this and i found the solution

raghunayudurayapudi avatar Jul 03 '17 17:07 raghunayudurayapudi

For anyone facing this issue, best way to handle is adding this at the end of the command: --module app.module.ts

Source

AlQuraian avatar Jul 24 '17 11:07 AlQuraian

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 /cname --skip-import

But I want modules to import in the directives or declarations and other than what fabbballin has suggested, is there any other way?

RakeshDeshpande avatar Nov 08 '17 07:11 RakeshDeshpande

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.

aaronglang avatar Nov 21 '17 21:11 aaronglang

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.