I am encountering an issue with my Angular application. Everything runs smoothly with `ng serve`, and the application builds correctly using `ng build --prod`. However, when I attempt to run the generated sources in the browser, an error occurs:
TypeError: $m.Subject is not a constructor
at new e (error-handling.service.ts:8)
... (additional error stack trace here)
The code snippet from `error-handling.service.ts` causing this error is as follows:
import { Injectable } from "@angular/core";
import { Subject } from "rxjs/Subject";
@Injectable({
providedIn: "root",
})
export class ErrorHandlingService {
private errors: Subject<string[]> = new Subject(); // <-- error in this line
constructor() {}
public addErrors = (errors: string[]): void => this.errors.next(errors);
public getErrors = () => this.errors.asObservable();
}
This code used to work fine on Angular 9, but after upgrading to version 10 (which also updated TypeScript), it stopped working. It's puzzling why it functions with `ng serve` but fails in production. Additionally, it's strange that this error isn't caught during compilation.
I have disabled Ivy for my project.