Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Runtime Error Cannot find module "ionic-native" IONIC 2

Tags:

ionic2

admob

I have been trying to add banner ads for the new ionic 2 apps but It display bellow error. i am doing it as shown here tutorial. but when i run it from browser using ionic serve -l -c its showing Runtime Error Cannot find module "ionic-native" error as bellow,

enter image description here

here is myapp.component.ts files 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.json file,

 "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"
],
like image 306
alka vaghela Avatar asked Mar 10 '23 10:03

alka vaghela


1 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)
   })
like image 127
Suraj Rao Avatar answered Apr 25 '23 15:04

Suraj Rao