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

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

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19

Commits related to this issue

Most upvoted comments

try ng g component hi --module app

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

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.

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!

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’