Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.4.0-beta.2] "more than one module matches" error when it should not #7439

Closed
cexbrayat opened this issue Aug 19, 2017 · 19 comments · Fixed by angular/devkit#115
Closed

[1.4.0-beta.2] "more than one module matches" error when it should not #7439

cexbrayat opened this issue Aug 19, 2017 · 19 comments · Fixed by angular/devkit#115

Comments

@cexbrayat
Copy link
Member

Bug Report or Feature Request (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.4.0-beta.2
node: 8.4.0
os: darwin x64

Repro steps.

ng g component hello                                                                                                                                 
  create src/app/hello/hello.component.css (0 bytes)
  create src/app/hello/hello.component.html (24 bytes)
  create src/app/hello/hello.component.spec.ts (621 bytes)
  create src/app/hello/hello.component.ts (265 bytes)
  update src/app/app.module.ts (392 bytes)

ng g module shared
  create src/app/shared/shared.module.ts (190 bytes)

ng g component hi 
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.

The log given by the failure.

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.

Desired functionality.

Using 1.3.x the same command adds the component to the root module.

installing component
  create src/app/hi/hi.component.css
  create src/app/hi/hi.component.html
  create src/app/hi/hi.component.spec.ts
  create src/app/hi/hi.component.ts
  update src/app/app.module.ts
@mode777
Copy link

mode777 commented Aug 23, 2017

I got exactly the same issue. (Coincidentally my module is also called shared ;))

@angular/cli: 1.4.0-beta.2 (also tested with beta.1)
node: 7.10.0
os: win10 x64

Reverting to 1.3.1 as a workaround

@m-ghaoui
Copy link

m-ghaoui commented Sep 11, 2017

I have this issue running @angular/cli 1.4.1 on Windows 10.

Has this fix been released?

For now I'm reverting to 1.3.2, which works

@fabianosandi
Copy link

I have with @angular/cli 1.4.2 on Windows 8.1

I did just like @m-ghaoui and now works!

@dekonunes
Copy link

try ng g component hi --module app

@babupca
Copy link

babupca commented Sep 16, 2017

I have component folder and with in that i have different component folder and with in that i have shared folder where i have the shared components like header, menu, etc, so with that if i try to created it is throwing the same error. Do you have any solution for this

src-->app --> components -> shared
--> header
--> footer
--> menu
--> services

ng g c src\app\components\shared\services
not only here if i try from project folder(where we give ng commands) too i get the same error.
kindly advise

@palzalus
Copy link

This is not really a complete solution but you can run ng g c hi --spec false --skip-import
After that you will need to add the import to your declarations yourself still.
Worked for me with @angular/cli 1.4.2.
Got the same error after i added app.server.module.ts to the root folder for angular universal.

@m98
Copy link

m98 commented Sep 17, 2017

As the warning says, It's because you have more than one module

You can solve it by specifying the name of the module you want to import the component to it.
ng generate component componentName --module=app.module

@rotomoco
Copy link

i've the same issue,
because i have the "app.module.ts" AND the "material.module.ts" in the app-folder.
i have temporaly delete the material.module.ts...
so it goes!

@m98
Copy link

m98 commented Sep 23, 2017

@rotomoco

Did not you try the way I suggested in the comment above?

@rotomoco
Copy link

yes, this will work too, but ive created now a new folder for the other modules and import it..
thank you, this will help too!!

@kamok
Copy link

kamok commented Oct 18, 2017

@m98 I had same problem with another .module.ts. Is there a better way than using the --module=app.module on every single ng g? I will probably just move my material.module.ts to somewhere else if not.

@rotomoco
Copy link

Add manualy a new folder, like app/shared and paste your material.module.ts in it.
So, import this module where you want but you have to change the the path to it, like : ....from './ shared/ Material.module'

@JaveedIshaq
Copy link

i am using Ubuntu, and following command solves the issue for me
ng generate component componentName --module=app.module

As the warning says, It's because you have more than one module
We can solve it by specifying the name of the module you want to import the component to it.

@mattmcsparran
Copy link

mattmcsparran commented Nov 4, 2017

Is there some way to set a default module we want to generate components to? Some option in a config? i see the "--module=app.module" option, and I don't have a problem using it. It would just be nice if there was a way to set a default. Because in previous versions, even if there were multiple modules in the root directory, it would still default to app.module.

@NilsNaegele
Copy link

NilsNaegele commented Dec 26, 2017

I'm on the newest version of angular everything. nothing resolves. first generating services in a module and now generating components.
Angular CLI: 1.6.2
Node: 8.3.0
OS: linux x64
Angular: 5.1.2
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router

@angular/cdk: 5.0.2
@angular/cli: 1.6.2
@angular/flex-layout: 2.0.0-beta.12
@angular/language-service: 4.4.6
@angular/material: 5.0.2
@angular-devkit/build-optimizer: 0.0.36
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.40
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.2
@schematics/angular: 0.1.11
@schematics/schematics: 0.0.11
typescript: 2.4.2
webpack: 3.10.0
is it this line in my package.json file: angular-devkit/schematics: "0.0.40" ?

@webrexRavi
Copy link

ng generate component componentName --module=app.module
this is solved my issue need to define the module in which you want to create this component.

@brionmario
Copy link

If you are trying to create a shared folder and add your shared components inside it, generate a module inside the shared folder first. (ex: ng g m shared)
Then try creating the components.

@ray-grod
Copy link

I got this issue when I created my material module under source/app, generate component couldn't decide between app module or my material module to put the import in to, so it kept giving me this error no matter what the component name was. I moved my material module to src/app/modules and it fixed this issue

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.