Angular-cli: [1.4.0-beta.2] "more than one module matches" error when it should not

Created on 19 Aug 2017  路  19Comments  路  Source: angular/angular-cli

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

Most helpful comment

try ng g component hi --module app

All 19 comments

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

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

I have with @angular/cli 1.4.2 on Windows 8.1

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

try ng g component hi --module app

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 srcappcomponentssharedservices
not only here if i try from project folder(where we give ng commands) too i get the same error.
kindly advise

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.

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

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!

@rotomoco

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

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!!

@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.

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'

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.

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.

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" ?

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._

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.

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

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

Related issues

JanStureNielsen picture JanStureNielsen  路  3Comments

rwillmer picture rwillmer  路  3Comments

sysmat picture sysmat  路  3Comments

5amfung picture 5amfung  路  3Comments

gotschmarcel picture gotschmarcel  路  3Comments