I'm having an issue with an Ionic 4, Cordova, Angular6 app. After cordova-plugin-facebook4 installation and addition to the app.module.ts file the TS compiler produces the following error:
[ng] ℹ 「wdm」: Compiled successfully. [ng] ERROR in src/app/app.module.ts(13,11): error TS2345: Argument of type '{ declarations: (typeof AppComponent)[]; entryComponents: undefined[]; imports: (ModuleWithProvid...' is not assignable to parameter of type 'NgModule'. [ng] Types of property 'providers' are incompatible. [ng] Type '(typeof SplashScreen | FacebookOriginal | { provide: typeof RouteReuseStrategy; useClass: typeof ...' is not assignable to type 'Provider[]'. [ng] Type 'typeof SplashScreen | FacebookOriginal | { provide: typeof RouteReuseStrategy; useClass: typeof I...' is not assignable to type 'Provider'. [ng] Type 'FacebookOriginal' is not assignable to type 'Provider'. [ng] Type 'FacebookOriginal' is not assignable to type 'ClassProvider'. [ng] Property 'provide' is missing in type 'FacebookOriginal'.
This is my configuration:
✔ Gathering environment info - done!
Ionic:
ionic (Ionic CLI) : 4.1.2 (/usr/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 4.0.0-beta.7
@angular-devkit/core : 0.7.5
@angular-devkit/schematics : 0.7.5
@angular/cli : 6.1.5
@ionic/ng-toolkit : 1.0.8
@ionic/schematics-angular : 1.0.6
Cordova:
cordova (Cordova CLI) : 8.1.1 ([email protected])
Cordova Platforms : android 7.1.1
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.2.0, (and 4 other plugins)
This is app.module.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule, RouteReuseStrategy, Routes } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { Facebook } from '@ionic-native/facebook';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [
BrowserModule,
IonicModule.forRoot(),
AppRoutingModule
],
providers: [
StatusBar,
SplashScreen,
Facebook,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
bootstrap: [AppComponent]
})
export class AppModule {}
Also this package is installed and available in package.json file:
"@ionic-native/facebook": "^4.15.0"
Thanks in advance for your opinions.
However, Ionic Native (and therefore, Cordova plugins) can still be used. Vanilla JavaScript apps, targeting ES2015+ and/or TypeScript, can use either Cordova or Capacitor to build native mobile apps. To use any plugin, import the class from the appropriate package and use its static methods:
This is a fork of the official plugin for Facebook in Apache Cordova that implements the latest Facebook SDK. Unless noted, this is a drop-in replacement. You don't have to replace your client code.
All plugins have two components - the native code (Cordova) and the TypeScript code (Ionic Native). Cordova plugins are also wrapped in a Promise or Observable in order to provide a common plugin interface and modernized development approach. Next, begin using the plugin, following the various framework usage options below. For FAQ, see here.
After, you'll need to add the native platforms you'll be using to your app in the Facebook Developer portal under your app's Settings: Click 'Add Platform'. At this point you'll need to open your project's config.xml file, found in the root directory of your project.
I managed to figure this out: The include should be done from the 'ngx' folder for the ionic-native Facebook module, like this:
import { Facebook } from '@ionic-native/facebook/ngx';
This is not available in any documentation of the module.
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