Runtime error Unable to find the "ionic-native" IONIC 2 module

I am trying to add banner ads for new ionic 2 applications, but it displays the following error. I do this as the tutorial shown here . but when I launch it from the browser using ionic serve -l -c, it shows an error Runtime Error Cannot find module "ionic-native"as shown below,

enter image description here

here is my app.component.tsfile code

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { Geolocation } from '@ionic-native/geolocation';
import { AdMob } from 'ionic-native';


import { HomePage } from '../pages/home/home';
import { DetailsPage } from '../pages/details/details';
import { SettingModalPage } from '..Pages/setting-modal/setting-
modal';


@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = HomePage;

constructor(platform: Platform, statusBar: StatusBar, splashScreen: 
SplashScreen) {
platform.ready().then(() => {
  // Okay, so the platform is ready and our plugins are available.
  // Here you can do any higher level native things you might need.
  statusBar.styleDefault();
  splashScreen.hide();

  let options = {
    adId: 'ca-app-pub-5732334124058455/7973166445',
    adSize: 'SMART_BANNER',
    isTesting: false
  };

  AdMob.createBanner(options).then(() => {
    AdMob.showBanner(8);
  });

 });
}
}

in my package.jsonfile,

 "dependencies": {
"@angular/common": "2.4.8",
"@angular/compiler": "2.4.8",
"@angular/compiler-cli": "2.4.8",
"@angular/core": "2.4.8",
"@angular/forms": "2.4.8",
"@angular/http": "2.4.8",
"@angular/platform-browser": "2.4.8",
"@angular/platform-browser-dynamic": "2.4.8",
"@angular/platform-server": "2.4.8",
"@ionic-native/admob": "^3.4.4",
"@ionic-native/core": "^3.1.0",
"@ionic-native/geolocation": "^3.4.4",
"@ionic-native/launch-navigator": "^3.4.4",
"@ionic-native/splash-screen": "3.1.0",
"@ionic-native/status-bar": "3.1.0",
"@ionic/storage": "2.0.0",
"font-awesome": "^4.7.0",
"ionic-angular": "2.3.0",
"ionic2-rating": "^1.2.0",
"ionicons": "3.0.0",
"rxjs": "5.0.1",
"sw-toolbox": "3.4.0",
"zone.js": "0.7.2"
  },
  "devDependencies": {
"@ionic/app-scripts": "1.1.4",
"typescript": "2.0.9"
  },
  "cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-console",
"cordova-plugin-statusbar",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
+4
source share
2 answers

Check here .

import { AdMob } from 'ionic-native';

was in ionic-native 2.x.

do:

ionic plugin add cordova-plugin-admobpro --save
npm install --save @ionic-native/admob

and

import { AdMob, AdMobOptions, AdSize, AdExtras} from '@ionic-native/admob';//import

constructor(platform: Platform, statusBar: StatusBar, splashScreen: 
SplashScreen,admob:Admob)//inject in constructor.

   //and use
   let options:AdMobOptions={
    adId: 'ca-app-pub-5732334124058455/7973166445',
    adSize: 'SMART_BANNER',
    isTesting: false
   }
   this.admob.createBanner(options).then(()=>{
       this.admob.showBanner(8)
   })
+7
source

ionic-native . , :

import { AdMob } from 'ionic-native';

import { AdMob } from '@ionic-native/admob';

0

Source: https://habr.com/ru/post/1674195/


All Articles