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)
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.
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) {}
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
}