Object(…) is not a function ionic 3 network

I am trying to use Network plugin in my App to Check if there’s an Internet Connection or not but Whenever I try to Add it I am getting this error

 Object(...) is not a function
    at index.js:153
    at Object.<anonymous> (index.js:230)
    at __webpack_require__ (bootstrap 223aabd9577ce2607588:54)
    at Object.353 (main.js:5325)
    at __webpack_require__ (bootstrap 223aabd9577ce2607588:54)
    at Object.177 (utilities.service.ts:5)
    at __webpack_require__ (bootstrap 223aabd9577ce2607588:54)
    at Object.529 (app.module.ts:193)
    at __webpack_require__ (bootstrap 223aabd9577ce2607588:54)
    at Object.492 (profileStore.ts:9)

I am importing and using Network plugin like this

 import { Network } from '@ionic-native/network';
 export class Plugins {
 constructor(public network: Network) {}
    ionViewWillEnter(){
       if(this.checkInternet()){
    console.log('Active Connection')

    else{
    console.log('Connection Is not Active')}
    }
    }
    checkInternet() {
   let connectSubscription = this.network.onConnect().subscribe(() => {
  console.log('network connected!');
  setTimeout(() => {
    if (this.network.type === 'wifi') {
      console.log('we got a wifi connection, woohoo!');
    }
  }, 3000);
});

connectSubscription.unsubscribe();
              }
        }

Package.json

{
“name”: “Hello World”,
“version”: “0.0.1”,
“author”: “Ionic Framework”,
“homepage”: “http://ionicframework.com/”,
“private”: true,
“scripts”: {
“start”: “ionic-app-scripts serve”,
“clean”: “ionic-app-scripts clean”,
“build”: “ionic-app-scripts build”,
“lint”: “ionic-app-scripts lint”
},
“dependencies”: {
@angular/animations”: “6.1.10”,
@angular/common”: “6.1.10”,
@angular/compiler”: “6.1.10”,
@angular/compiler-cli”: “^6.1.10”,
@angular/core”: “6.1.10”,
@angular/forms”: “6.1.10”,
@angular/http”: “6.1.10”,
@angular/platform-browser”: “6.1.10”,
@angular/platform-browser-dynamic”: “6.1.10”,
@ionic-native/base64”: “^5.3.0”,
@ionic-native/core”: “~5.0.0”,
@ionic-native/http”: “^5.2.0”,
@ionic-native/network”: “^4.17.0”,
@ionic-native/screen-orientation”: “^5.3.0”,
@ionic-native/splash-screen”: “~5.3.0”,
@ionic-native/status-bar”: “~5.3.0”,
@ionic/storage”: “2.2.0”,
@types/lodash”: “^4.14.122”,
“angular2-color-picker”: “^1.3.1”,
“angular2-draggable”: “^2.2.1”,
“angular2-uuid”: “^1.1.1”,
“com-badrit-base64”: “0.2.0”,
“cordova-android”: “^8.0.0”,
“cordova-plugin-network-information”: “^2.0.2”,
“cordova-plugin-screen-orientation”: “^2.0.0”,
“es6-promise-plugin”: “^4.2.2”,
“html2canvas”: “^1.0.0-alpha.10”,
“install”: “^0.13.0”,
“ionic-angular”: “3.9.2”,
“ionic-long-press”: “^1.5.0”,
“ionicons”: “4.5.5”,
“lodash”: “^4.17.11”,
“mobx”: “3.0.1”,
“mobx-angular”: “^3.0.1”,
“ng-socket-io”: “^0.2.4”,
“ngx-color-picker”: “^7.3.1”,
“npm”: “^6.11.3”,
“rxjs”: “^6.3.3”,
“rxjs-compat”: “^6.3.3”,
“sw-toolbox”: “3.6.0”,
“zone.js”: “0.8.26”
},
“devDependencies”: {
@ionic/app-scripts”: “3.2.3”,
@ionic/cli-plugin-cordova”: “1.6.2”,
@ionic/cli-plugin-ionic-angular”: “1.4.1”,
@types/node”: “~8.9.4”,
“cordova-plugin-advanced-http”: “2.0.5”,
“cordova-plugin-device”: “2.0.2”,
“cordova-plugin-ionic-keyboard”: “^2.0.5”,
“cordova-plugin-ionic-webview”: “^2.0.0”,
“cordova-plugin-splashscreen”: “5.0.2”,
“cordova-plugin-statusbar”: “2.4.2”,
“cordova-plugin-whitelist”: “1.3.3”,
“ts-node”: “~5.0.1”,
“typescript”: “^2.7.2”
},
“description”: “An Ionic project”,
“cordova”: {
“plugins”: {
“cordova-plugin-screen-orientation”: {},
“cordova-plugin-whitelist”: {},
“cordova-plugin-statusbar”: {},
“cordova-plugin-device”: {},
“cordova-plugin-splashscreen”: {},
“cordova-plugin-ionic-webview”: {
“ANDROID_SUPPORT_ANNOTATIONS_VERSION”: “27.+”
},
“cordova-plugin-ionic-keyboard”: {},
“cordova-plugin-advanced-http”: {},
“cordova-plugin-network-information”: {}
},
“platforms”: [
“android”
]
}
}

I Have tried to downgrading @ionic-native/network version but it doesn’t seem to work
Any Help Would Be Appreciated.

Bad idea. All @ionic-native parts must be on the same major version. Your import is missing a trailing /ngx.

How can I fix this issue?

uninstall and install it then try again might be work

I have already that but nothing seems to work

Try to downgrade plugin to 4.20.0 like this :

npm uninstall @ionic-native/network

then
npm install @ionic-native/network@4.20.0

And remove ngx in import like this :
import { Network } from '@ionic-native/network';

2 Likes

he did’t added ngx, maybe he added ionic 4 plugin in 3 and imported as ionic 3, so mr. @theCoder1 uninstall plugin install as @prashant714 said.

2 Likes

This is working for me!
Thanks