1

I have an Angular 4 project which at first I was able to use the ng generate component command but since I have implemented Routing the command no longer works as I get the following 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.

I'm not too sure if its the Routing that is causing this but that's all I can seem to put my finger on and I need to get it fixed

1
  • You can tell angular which module would you wan to add the newly component by ng g c newComponent --module targetModuleName Commented Apr 12, 2018 at 8:57

3 Answers 3

3

The error speaks for itself, as you have at least two modules in your project. You need to use the skip-import flag because Angular is unable to decide for what module it should be imported. After you added the skip-import flag, the error will be gone. But you will have to manually import the component into the module you wish to utilize it in.

Like this:

ng generate component newComponent --skip-import

Sign up to request clarification or add additional context in comments.

1 Comment

I haven't already got the module though as I checked. First thing I did was to check. I tired creating one using 'abcdefantony' (very unique) but still got the above error
0

Try to run ng g component ComponentName inside the module folder.

1 Comment

tried but still get the error. File name I was using has not been used before as I was trying to use the following ng g component four0four
0

It is working for me using VS 2017 on Windows 10 with @angular/cli (6.0.8):

ng g c components/name-component ---module ../app/app.shared.module.ts

And run this command from ...\ClientApp\app

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.