transloco: Error: No provider for InjectionToken TRANSLOCO_TRANSPILER!

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
[ ] Other... Please describe:

Current behavior

I use TranslocoRootModule in my app module, when i run my application it works perfectly. like this:

@NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, AppRoutingModule, BrowserAnimationsModule, HttpClientModule, TranslocoRootModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }

But when i try to test AppComponent i do this module initiation:

` beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ RouterTestingModule, TranslocoRootModule ], declarations: [AppComponent]

}).compileComponents()

})) `

And then when i run my tests i get this:

NullInjectorError: R3InjectorError(DynamicTestModule)[TranslocoService -> InjectionToken TRANSLOCO_TRANSPILER -> InjectionToken TRANSLOCO_TRANSPILER]: NullInjectorError: No provider for InjectionToken TRANSLOCO_TRANSPILER! error properties: Object({ ngTempTokenPath: null, ngTokenPath: [ 'TranslocoService', 'InjectionToken TRANSLOCO_TRANSPILER', 'InjectionToken TRANSLOCO_TRANSPILER' ] }) at <Jasmine> at NullInjector.get (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:1085:1) at R3Injector.get (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:16955:1) at R3Injector.get (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:16955:1) at injectInjectorOnly (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:940:1) at Module.ɵɵinject (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:950:1) at Object.TranslocoService_Factory [as factory] (http://localhost:9876/_karma_webpack_/node_modules/@ngneat/transloco/__ivy_ngcc__/fesm2015/ngneat-transloco.js:1341:152) at R3Injector.hydrate (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:17193:42) at R3Injector.get (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:16943:1) at NgModuleRef$1.get (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:36329:1) at Object.get (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:33972:1)

I don’t get how when i run my app it works, but when running tests it doesnt, i also tried to follow the transloco tutorial for testing and did this:

` function getTranslocoModule(config: Partial<TranslocoConfig> = {}) { return TranslocoTestingModule.withLangs( {he, en}, { availableLangs: [‘he’, ‘en’], defaultLang: ‘he’, fallbackLang: ‘he’, reRenderOnLangChange: true, …config }, ).providers = [{ provide: TRANSLOCO_TRANSPILER, useClass: DefaultTranspiler }] }

beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ RouterTestingModule, getTranslocoModule() ], declarations: [AppComponent]

}).compileComponents()

})) `

also didnt work…

Expected behavior

Transloco module should be injected normally without any exceptions

Minimal reproduction of the problem with instructions

For bug reports please provide the STEPS TO REPRODUCE and if possible a MINIMAL DEMO of the problem, for that you could use our stackblitz example

What is the motivation / use case for changing the behavior?

Environment


Angular version: X.Y.Z


Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (1 by maintainers)

Most upvoted comments

@rami-almofleh @pnocera The TranslocoModule doesn’t provide these providers. please look at the docs, you need to use provideTransloco.

when you say REGISTER do you mean added it as a token injected provider to app.module?