Repository navigation
Closed
Labels
Milestone
Description
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
We noticed that inject(XYZ, { optional: true }) does not work if the given ProviderToken is using useExisting to refer to another, unavailable ProviderToken.
We would have expected the given inject call to just return null in case the aliased ProviderToken is not available. Instead NullInjectorError and an erroneous Error: NG0200 are thrown.
According to the inject functions documentation, it should not throw DI Errors if called with optional injection.
The erroneous NG0200 is caused by the first error leaving the Injectors record in the creating state.
Please provide a link to a minimal reproduction of the bug
Please provide the exception or error you saw
error1 NullInjectorError: R3InjectorError(Environment Injector)[InjectionToken relayed injectable -> InjectionToken base injectable -> InjectionToken base injectable]:
NullInjectorError: No provider for InjectionToken base injectable!
Angular 16
_PlaygroundComponent main.ts:15
PlaygroundComponent_Factory main.js:34222
Angular 41
<anonymous> main.ts:29
main.ts:18:20
error2 Error: NG0200: Circular dependency in DI detected for InjectionToken relayed injectable. Find more at https://angular.dev/errors/NG0200
Angular 10
_PlaygroundComponent main.ts:21
PlaygroundComponent_Factory main.js:34222
Angular 41
<anonymous> main.ts:29
Please provide the environment you discovered this bug in (run ng version)
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 19.2.5
Node: 20.19.1
Package Manager: npm 10.8.2
OS: linux x64
Angular: 19.2.4
... animations, common, compiler, compiler-cli, core, forms
... platform-browser
Package Version
------------------------------------------------------
@angular-devkit/architect 0.1902.5
@angular-devkit/core 19.2.5
@angular-devkit/schematics 19.2.5
@angular/build 19.2.5
@angular/cdk 19.2.7
@angular/cli 19.2.5
@angular/material 19.2.7
@schematics/angular 19.2.5
rxjs 7.8.2
typescript 5.8.2
zone.js 0.15.0
Anything else?
No response
Activity
fix(core): missing useExisting providers throwing for optional calls (a…
fix(core): missing useExisting providers throwing for optional calls
fix(core): missing useExisting providers throwing for optional calls (#…
angular-automatic-lock-bot commentedon Jun 6, 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.