angular: Can't resolve all parameters for .... This will become an error in Angular v6.x
I’m submitting a…
[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:
I have 4 classes:
- Class A, @Injectable
- Class B, abstract, NON injectable, extends A
- Class C, @Injectable, extends B
- Class D, @Injectable, extends B
classes A, C and D are used as Services and correctly added to the providers
list of my module. Class B is NOT used as a service.
Current behavior
Everything works fine but I got this warning:
Can’t resolve all parameters for ClassBService in /path/to/class-b.service.ts: ([object Object], ?). This will become an error in Angular v6.x
Expected behavior
Not sure if some action on my side is required or this warning should not be displayed.
Demo
Clone the repository, run npm install
and then ng build --prod
. You’ll see the warning.
https://github.com/ShinDarth/angular-test/
https://github.com/ShinDarth/angular-test/commit/4101bc56cd9f9a13915017ee40c6a90b51d363c5
Environment
Angular CLI: 1.7.4 Node: 8.10.0 OS: linux x64 Angular: 5.2.11 … animations, common, compiler, compiler-cli, core, forms … http, language-service, platform-browser … platform-browser-dynamic, router
@angular/cli: 1.7.4 @angular-devkit/build-optimizer: 0.3.2 @angular-devkit/core: 0.3.2 @angular-devkit/schematics: 0.3.2 @ngtools/json-schema: 1.2.0 @ngtools/webpack: 1.10.2 @schematics/angular: 0.3.2 @schematics/package-update: 0.3.2 typescript: 2.6.2 webpack: 3.11.0
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 11
- Comments: 24 (6 by maintainers)
If I can help someone… I solved my issue
I had this error. The problem for me was a missing
@Inject
.I created an InjectionToken to pass a config to my Service from the forRoot, but I was missing the
@Inject("myTokenName")
in my Service.So when building with
--aot
and--build-optimizer=true
or--build-optimizer=false
I had the warning!After adding the
@Inject
problem solved!!I had this issue because I am using generics to reduce code duplication. Here is my original code that was causing the warning:
Since this class is abstract it will never be injected anywhere, thus it should not be decorated with
@Injectable()
. Removing it makes compiler happy again.If you need
@Injectable
then@Inject
needs to be also provided - the solution proposed by @tonysamperi.Having this problem too. Angular 7 complaining only when ng build is called with --prod / --aot. Its still a warning (not an error), but its annoying to have logged. I can also confirm that its different to the duplicate tickets marked above.
It works, when you remove injectable decorator, then your abstract/generic class compiles successfully. Thanks.
I confirm that the bug is still present using Angular 7, and it’ still saying:
Same or similar problem here except that the error occurs at runtime (no problems reported from the compiler).
We have an abstract base class which looks like that (excerpt):
From this class the following class is derived:
This works with @angular-devkit/build-angular Version 0.802.2. After updating this package to 0.803.6 the following error occurs at runtime when starting the module which contains the CurrencyExchangeRateContainerComponent:
The solution for this problem: DI has to be performed on a class which has the
@Component
- Decorator!So, after changing the code as follows, everything works.
Base class:
Derived class:
I do not know if this “breaking change” is documented somewhere. It seems that it was introduced with the step from 0.802.2 > 0.803.6 of the package @angular-devkit/build-angular.
Result of ng --version:
I currently have the same issue with the following combination of classes:
The problem is that
MySpecialServiceImpl
inherits the@Injectable()
annotation and there is no way to prevent this or opt-out of the DI mechanics at some point in your class hierarchy. TheMySpecialServiceImpl
will never be created by some injector, it’s only created manually.Is there any other way to prevent this warning?
just FYI, the bug is still happening with: