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

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

Open cexbrayat opened this issue 9 years ago • 19 comments

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

cexbrayat avatar Aug 19 '17 13:08 cexbrayat

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

mode777 avatar Aug 23 '17 09:08 mode777

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

m-ghaoui avatar Sep 11 '17 14:09 m-ghaoui

I have with @angular/cli 1.4.2 on Windows 8.1

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

fabianosandi avatar Sep 14 '17 20:09 fabianosandi

try ng g component hi --module app

dekonunes avatar Sep 15 '17 03:09 dekonunes

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

babupca avatar Sep 16 '17 03:09 babupca

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.

palzalus avatar Sep 16 '17 08:09 palzalus

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

m98 avatar Sep 17 '17 07:09 m98

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 avatar Sep 23 '17 07:09 rotomoco

@rotomoco

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

m98 avatar Sep 23 '17 07:09 m98

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

rotomoco avatar Sep 23 '17 07:09 rotomoco

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

kamok avatar Oct 18 '17 19:10 kamok

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'

rotomoco avatar Oct 18 '17 20:10 rotomoco

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.

JaveedIshaq avatar Oct 31 '17 19:10 JaveedIshaq

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.

mattmcsparran avatar Nov 04 '17 03:11 mattmcsparran

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

NilsNaegele avatar Dec 26 '17 10:12 NilsNaegele

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.

webrexRavi avatar Jan 01 '18 06:01 webrexRavi

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.

brionmario avatar Feb 03 '18 17:02 brionmario

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

ray-grod avatar Oct 12 '18 03:10 ray-grod

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.