Repository navigation
Description
Which @angular/* package(s) are the source of the bug?
Don't known / other
Is this a regression?
Yes
Description
PR #61354 introduces a critical bug.
The application can't be started at all, the error occurs: "RuntimeError: NG0200: Circular dependency in DI detected for _ApplicationRef. Find more at https://angular.dev/errors/NG0200".
It seems the source of the problem is the code: private readonly appRef = inject(ApplicationRef);
Please provide a link to a minimal reproduction of the bug
The application is configured with provideHttpClient( withFetch(), withInterceptorsFromDi() ).
Exception occurs in method hydrate(token, record, flags) while resolving ApplicationRef in the FetchBackend class:
if (record.value === CIRCULAR) {
throwCyclicDependencyError(stringify(token));
The token here is the "class _ApplicationRef" and the record is the "{ factory: ƒ ApplicationRef_Factory(ngFactoryType), ... }".
Please provide the exception or error you saw
RuntimeError: NG0200: Circular dependency in DI detected for _ApplicationRef. Find more at https://angular.dev/errors/NG0200
at throwCyclicDependencyError (core.mjs:978:9)
at R3Injector.hydrate (core.mjs:2238:9)
at R3Injector.get (core.mjs:2121:23)
at injectInjectorOnly (core.mjs:1111:28)
at ɵɵinject (core.mjs:1117:40)
at inject (core.mjs:1202:10)
at <instance_members_initializer> (module-BQ-7fJZl.mjs:1620:12)
at new _FetchBackend (module-BQ-7fJZl.mjs:1612:1)
at Object.FetchBackend_Factory [as factory] (module-BQ-7fJZl.mjs:1832:12)
at core.mjs:2243:35
at runInInjectorProfilerContext (core.mjs:881:5)
at R3Injector.hydrate (core.mjs:2242:11)
at R3Injector.get (core.mjs:2121:23)
at injectInjectorOnly (core.mjs:1111:28)
at ɵɵinject (core.mjs:1117:40)
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 19.2.12 Node: 24.1.0 (Unsupported) Package Manager: npm 11.4.1 OS: win32 x64 Angular: 19.2.12 ... animations, cli, common, compiler, compiler-cli, core, forms ... platform-browser, router Package Version --------------------------------------------------------- @angular-devkit/architect 0.1902.12 @angular-devkit/build-angular 19.2.12 @angular-devkit/core 19.2.12 @angular-devkit/schematics 19.2.12 @schematics/angular 19.2.12 rxjs 7.8.2 typescript 5.8.3 zone.js 0.15.1
Anything else?
This is the regression, because prior to the version 19.2.12 application started successfully.
Activity
thePunderWoman commentedon May 23, 2025
@ZixZux This needs a minimal reproduction in order for us to look deeper. Please create a stackblitz and link it here.
ZixZux commentedon May 23, 2025
I've described what is happened in the section "Please provide a link to a minimal reproduction of the bug".
Once more: the bug doesn't exist before PR #61354.
thePunderWoman commentedon May 23, 2025
@ZixZux Description is not enough. We need a functioning reproduction of the bug to dig through. Please create that for us otherwise this is not actionable.
JeanMeche commentedon May 23, 2025
The minimal repro:
arturovt commentedon May 23, 2025
@JeanMeche fine, I'll inject it lazily then
fix(common): inject `ApplicationRef` lazily in `FetchBackend`
fix(common): inject `ApplicationRef` lazily in `FetchBackend`
ZixZux commentedon May 23, 2025
Thanks!
fix(common): avoid injecting ApplicationRef in FetchBackend
fix(common): avoid injecting ApplicationRef in FetchBackend
fix(common): avoid injecting ApplicationRef in FetchBackend
fix(common): avoid injecting ApplicationRef in FetchBackend (#61649)
fix(common): avoid injecting ApplicationRef in FetchBackend (#61649)
fix(common): avoid injecting ApplicationRef in FetchBackend (angular#…
ZixZux commentedon May 26, 2025
btw, why angular CI/CD doesn't have such a simple smoke/sanity tests?..
JeanMeche commentedon May 26, 2025
This could be seen as an edge case. The circular injection required 3 specific pieces.
Also because the root cause has already been solved on v20, we couldn't not leverage the google code base to test this.
Any way, we added a test case for it.
ZixZux commentedon May 26, 2025
"The circular injection required 3 specific pieces."
I'm sure it's the key marker to have such tests initially...
wartab commentedon May 26, 2025
Angular is an open source project, feel free to contribute tests you feel are missing.
ZixZux commentedon May 26, 2025
it's just very strange to hear (put it mildly) that using
withFetch()andErrorHandler"could be seen as an edge case"...i'm sure majority applications using these artifacts.
angular-automatic-lock-bot commentedon Jun 26, 2025
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.