rxjs - Angular 19 `toObservable` causing `ng build` error TypeError: r.notifier.notify is not a function - Stack Overflow

The following code:import { toObservable } from '@angularcorerxjs-interop';...export cla

The following code:

import { toObservable } from '@angular/core/rxjs-interop';
...
export class MyService {
  readonly myData= signal<MyData| null>(null);
  // toObservable creates a cold observable. Use startWith to make it function as a BehaviorSubject.
  readonly myData$ = toObservable(this.myData).pipe(startWith(this.myData()));

Causes an error on ng build:

X [ERROR] An error occurred while extracting routes
TypeError: r.notifier.notify is not a function
    at ** (file:///C:/Users/**/.angular/prerender-root/**/chunk-**.mjs:34:86300)
    ....

I am not entirely sure how to move forward from this other than ditch the function toObservable for now. It seems that it fails at prerendering or some other phase of the ng build. The r.notifier.notify is already internal to Angular and is beyond the scope of the application layer.

The following code:

import { toObservable } from '@angular/core/rxjs-interop';
...
export class MyService {
  readonly myData= signal<MyData| null>(null);
  // toObservable creates a cold observable. Use startWith to make it function as a BehaviorSubject.
  readonly myData$ = toObservable(this.myData).pipe(startWith(this.myData()));

Causes an error on ng build:

X [ERROR] An error occurred while extracting routes
TypeError: r.notifier.notify is not a function
    at ** (file:///C:/Users/**/.angular/prerender-root/**/chunk-**.mjs:34:86300)
    ....

I am not entirely sure how to move forward from this other than ditch the function toObservable for now. It seems that it fails at prerendering or some other phase of the ng build. The r.notifier.notify is already internal to Angular and is beyond the scope of the application layer.

Share Improve this question edited Mar 3 at 8:29 jonrsharpe 122k30 gold badges268 silver badges476 bronze badges asked Mar 3 at 8:03 Alex PappasAlex Pappas 2,7073 gold badges31 silver badges61 bronze badges 2
  • Have you tried deleting the .angular-cache folder? – Silvermind Commented Mar 3 at 8:17
  • 1 yes. that, npm cache clean, and all sorts of potential caching issues. I made sure it is indeed this exact function causing it just by removing the code and rebuilding. – Alex Pappas Commented Mar 3 at 8:25
Add a comment  | 

1 Answer 1

Reset to default 1

My guess is that you're injecting that service into an ErrorHandler.

toObservable is pulling effect and is creating a cyclic dependency injection within Angular.

So the solution should be to somehow break that cyclic DI by delaying the injection of MyService with a Injector.get(MyService) instead.

On the framework side this issue should be addressed by 2 PRs:

  • https://github/angular/angular/pull/58984 To instantiate the ErrorHandler lazily which would break the cyclic DI
  • https://github/angular/angular/pull/60118 The Cyclic DI error should be thrown in prod mode

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745104760a4611490.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信