the code was running fine on angular version 8.3.4 but when i updated it to the latest version of angular ( 9 ) i got the following error

following is the stack trace

core.js:3866 ERROR Error: Uncaught (in promise): Error: Multiple components match node with tagname app-lobby Error: Multiple components match node with tagname app-lobby at throwMultipleComponentError (core.js:5511) at findDirectiveDefMatches (core.js:8276) at resolveDirectives (core.js:8080) at elementStartFirstCreatePass (core.js:14215) at ɵɵelementStart (core.js:14249) at Module.ɵɵelement (core.js:14324) at MainComponent_Template (main.component.html:1) at executeTemplate (core.js:7562) at renderView (core.js:7387) at renderComponent (core.js:8577) at resolvePromise (zone.js:836) at resolvePromise (zone.js:795) at zone.js:897 at ZoneDelegate.invokeTask (zone.js:431) at Object.onInvokeTask (core.js:27769) at ZoneDelegate.invokeTask (zone.js:430) at Zone.runTask (zone.js:198) at drainMicroTaskQueue (zone.js:611) at ZoneTask.invokeTask (zone.js:517) at ZoneTask.invoke (zone.js:502) 
11

13 Answers

Probably you have more than one component with the same selector tag name app-lobby

... @Component({ selector: 'app-lobby', ... 

Please double check to ensure that only one component selector tag name is app-lobby.

3

The two answers above about declaring DatePipe in providers should be considered. Today I met this problem (Angular 9) when adding an argument private datePipe: DatePipe in the constructor of my component without declaring DatePipe in the module's provider. After adding DatePipe in providers, I have no more the problem.

The constructor :

constructor(private authenticationService: AuthenticationService, private datePipe: DatePipe) {} 
2

This error actually has less to do with the tagname app-lobby. I encountered this error when I applied multiple component selector on a html tag.

For example: Component 1

@Component({ ... selector: '[my-tooltip]', ... }) 

Component 2

@Component({ ... selector: '[my-button]', ... }) 

Notice that both of them are angular component yet having a selector like attribute directive.

When you apply both of them on the same tag like below:

<button my-button my-tooltip="Some tooltip">Hover me</button> 

Then angular complains about applying 2 components on a single tag. In this case it will complain about button tag, like: Error: Multiple components match node with tagname button

The solution would be not to use multiple component selector on a single element.

I had the exact same error saying Error: Multiple components match node with tagname <my-tagname> and I checked way too long that this tag is in fact unique. After reading over this question and all answers for the second time, I found @Eugen's comment to the original question and that finally helped me. So I'm adding this here with a little example in case everyone has this problem in the future. Angular's error message doesn't really help here.

My mistake was that I had injected a service into my component and used it directly in the constructor like so:

constructor(private myService: MyService) { this.myService.doSomething() } 

That doesn't work because it introduces a race condition between Angular's dependency injection and me wanting to use the service in the constructor. Inside the constructor, the service is not instantiated yet.

What you want to do is use that service after the constructor has been called, i.e. in Angular's OnInit-hook:

export class MyComponent implements OnInit { constructor(private myService: MyService) {} ngOnInit(): void { this.myService.doSomething(); } // Rest of the component } 

Maybe not directly related, but I got the same error in unit tests, where I was testing few of my components with Router using Angular 11. The error was Error: NG0300: Multiple components match node with tagname button

This was super confusing since button is native element so it didn't point me anywhere. After a lot of struggle and few changes that I did to narrow down the problem, I found that the root cause for this was NG0302: The pipe 'formatPrice' could not be found!.. I added the pipe and my tests worked again.

So if this happens to you while testing, double check if you declared all directives used in components that you have under test.

For me following steps worked in a Angular 11 project :

  1. First I searched for duplicate tag name across the project, found none.
  2. Then I removed the line where the component was used and causing error.
  3. Saved and Compiled it. Ensured that error is gone.
  4. Pasted back the line. Recompiled and got a dependency error: xyz service not found. Added the dependency in app modules in providers array.

And that resolved the error.

What was wrong in my case when I encountered this error:

I had another DI error (NullInjectorError). @eugen's comment on the question helped me.

Tip: See if you have a preceding error in developer console before this "Multiple components match ..." error. Usually such errors are reported only by JIT during runtime (when in dev mode), so you'll only spot them in the browser's developer console.


PS: Don't provide the DatePipe again in your own module as it's already provided by angular's CommonModule. So check if you are missing the CommonModule import in your module.

My issue was that I was declaring in the test a mocked component with that tag and at the same time importing a module that declared the actual component. Removing the module fixed it.

1

@VikasBhardwaj I had same problem in Angular 9 because I have created lobby page and lobby component. In this case, app-lobby is duplicated in pages and components.

@Component({ selector: 'app-feed', 

So I have changed page name as lobbies, so the problem is fixed.

I have solved by changing the component selector. But i guess the problem was inside some imported module, component or library.

As documentation says, this error is caused by a repeated selector, but after checking several times, I was sure i have no repeated selectors (at least inside my project files) so the only option left is that my selector's name was used by some other component which I was importing.

I had the same issue on an Angular 12 project (with Ivy enabled). The selector was unique, but as it turned out, I was importing the component from two different manners:

  • once from a relative file (e.g import { MyComponent } from ./lib/my-component
  • once using a typescript path alias (e.g import { MyComponent } from @my-library/my-component)

So if in your tsconfig.json file, you have defined a path alias make sure to use it in every import or else you'll have the issue.

I have an app in angular 9. I had similar problem, but then i realised that i forgot the provider for DatePipe. After that, this error went away... Maybe errors like these won't be happening after some time of angular 9 development.

Add DatePipe in the providers.It will work fine.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy