Angular threw this error because it tried to insert a DOM node next to another node it was tracking, and that node isn't where Angular expects it to be anymore.
Angular keeps track of the DOM nodes it renders so it knows where to insert, move, or remove things later, for example when a @for block re-renders. If something outside Angular changes that part of the DOM (removes a node, moves it somewhere else), Angular's internal record goes stale. The next time it tries to insert next to that node, you get this error instead of a confusing native NotFoundError.
This can happen because of:
- App code touching the DOM directly (
ElementRef.nativeElement,document.querySelector,innerHTML, etc.) instead of going through Angular. - A browser extension messing with the page, like a translation tool, a grammar checker, or a password manager.
- An edge case in Angular itself, in code that reorders or conditionally renders views (
@for,@if, dynamically created views).
The following example triggers the error:
@Component({
selector: 'app-example',
template: `@if (show) {
<span>{{ text }}</span>
}`,
})
export class Example {
show = true;
text = 'hello';
hostElement = inject(ElementRef).nativeElement;
ngAfterViewInit() {
// Removing this node behind Angular's back is what causes the error.
this.hostElement.querySelector('span').remove();
}
}
Debugging the error
The error message tells you which node Angular expected to find, so start there.
- Look for code in this component (or a parent) that touches the DOM directly instead of using Angular APIs, and switch it to use those instead.
- If the error only shows up for some users, or you can reproduce it locally with an extension installed, try an incognito window with extensions turned off.
- If it happens consistently on the same route for many different users, it's probably not an extension (those vary per user) — look for something deterministic in that page instead, like a
@for/@ifthat reorders or removes content in an unusual way, or a third-party widget embedded on that page. - If none of the above explains it, please file an issue with a reproduction.