Getting the error after updating to Angular 9 / Ivy compiler
ERROR Error: Token InjectionToken XXXXXXXXX is missing a ɵprov definition.
at injectableDefOrInjectorDefFactory (vendor.js:47105)
at providerToFactory (vendor.js:47210)
at resolveProvider$1 (vendor.js:56430)
This can occur if you try to explicitly override an inherited injectable with undefined
or null
.
In Angular 8 this was ok
{
provide: AMBIENT_CART,
useExisting: undefined
}
With Angular 9 it needs to be changed to
{
provide: AMBIENT_CART,
useValue: undefined
}
If you're curious: In my case I was doing this for safety reasons, to make sure I didn't use this particular injectable by mistake.
I got the same error when running ng test after upgrading from Angular 8 --> 9: "Error: Token InjectionToken apiToken is missing a ɵprov definition."
My solution to this was very simple- there was a typo in the spec file that I guess didn't matter in Angular 8, but does in Angular 9? The last instance of 'useValue' below was incorrectly written 'usevalue'. Such an obscure error!
TestBed.configureTestingModule({
imports: [ HttpClientTestingModule ],
providers: [
{ provide: ApiService, useValue: apiService },
{ provide: ProductsApiService, useValue: productsService },
{ provide: apiToken, useValue: mockApiToken }
]
});
I started receiving this error while running unit tests after upgrading an application from Angular 8 to Angular 10. The issue occurred because the existing spec file was using value
instead of useValue
in the providers array as shown in the below sample. Fixed the issue by changing it to useValue
.
beforeEach(async(() => {
void TestBed.configureTestingModule({
declarations: [
MockPipe(TranslatePipe),
],
imports: [
HttpClientTestingModule,
],
providers: [
FormBuilder,
MessageService,
{ provide: MESSAGES_TOKEN, value: {} }, //changed to useValue
]
}).compileComponents();
}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With