Issue
I suddenly started to receive these errors after I restarted my ionic app:
TS2322: Type 'FacebookOriginal' is not assignable to type 'Provider'. Type 'FacebookOriginal' is missing the following properties from type 'TypeProvider': apply, call, bind, prototype, and 5 more.
app.module
// More imports above
import {Facebook} from '@ionic-native/facebook/ngx'; <--- I triple checked that this is the correct import
@NgModule({
declarations: [
// List of components here
],
entryComponents: [],
imports: [
// List of modules here
],
providers: [
StatusBar,
SplashScreen,
IsLoggedInGuard,
FCM,
IsNotLoggedInGuard,
Facebook, // <----- Error here
{provide: RouteReuseStrategy, useClass: IonicRouteStrategy}
],
bootstrap: [AppComponent]
})
export class AppModule {
}
And where I inject the reference:
'Facebook' refers to a value, but is being used as a type here. Did you mean 'typeof Facebook'?
login.component.ts
// More imports above
import {Facebook} from '@ionic-native/facebook/ngx';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss'],
})
export class LoginComponent implements OnInit {
public datosBasicos: Basicos;
public colores: Color = new Color();
constructor(
public loginService: SessionService,
private router: Router,
private fb: Facebook, // <----- Error here
private platform: Platform,
private colorService: ColorService,
public basicosService: BasicosService
) {
}
async ngOnInit() {
// this.autologinIfPreview();
await this.loginService.loginAnonimo();
this.colores = this.colorService.color;
this.datosBasicos = await this.basicosService.findDatosBasicos().pipe(first()).toPromise();
}
public async loginFacebook() {
const fbResponse = await this.fb.login(['public_profile', 'user_friends', 'email']).then(); // Because of previous error, this isn't working at all
await this.loginService.loginFacebook(fbResponse);
this.router.navigate(['/main/home']).then();
// await this.loginService.loginFacebook();
}
If I add "typeof Facebook" this error appears at runtime:
This constructor is not compatible with Angular Dependency Injection because its dependency at index 2 of the parameter list is invalid. This can happen if the dependency type is a primitive like a string or if an ancestor of this class is missing an Angular decorator.
This error is driving me crazy, I was able to actually build the ionic app and perform a login with Facebook before. I tried to reinstall the plugin and types and change the version of them without any success.
Solution
Alright I got it!
Somewhere else in my application, I was using this:
session.service.ts
import {FacebookLoginResponse} from '@ionic-native/facebook'; // <--- Here!!! should be: '@ionic-native/facebook/ngx'
public async loginFacebook(facebookResponse: FacebookLoginResponse): Promise<User> {
if (facebookResponse) {
const facebookCredential = firebase.auth.FacebookAuthProvider.credential(facebookResponse.authResponse.accessToken);
const userCredential = await firebase.auth().signInWithCredential(facebookCredential);
return userCredential.user;
}
return null;
}
Hope this helps someone, this bug was a time waster
Answered By - Haytam95
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.