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

When I do this I get a bunch of errors like

Typescript Error
'>' expected.
C:/suplai-ra/suplai-A/node_modules/@ionic/core/dist/types/utils/overlays.d.ts
export declare const modalController: {
    create(options: ModalOptions<import("../interface").ComponentRef>): Promise<HTMLIonModalElement>;
    dismiss(data?: any, role?: string | undefined, id?: string | undefined): Promise<boolean>;

Any idea what is going on?

My package.json:

“scripts”: {

"start": "ionic-app-scripts serve",
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build --prod",
"lint": "ionic-app-scripts lint"

},

“dependencies”: {

"@angular/animations": "5.2.11",
"@angular/common": "5.2.11",
"@angular/compiler": "5.2.11",
"@angular/compiler-cli": "5.2.11",
"@angular/core": "^5.2.11",
"@angular/forms": "5.2.11",
"@angular/platform-browser": "5.2.11",
"@angular/platform-browser-dynamic": "5.2.11",
"@angular/router": "^9.1.12",
"@azure/cosmos": "^3.7.4",
"@azure/storage-blob": "^12.1.2",
"@ionic-native/camera": "4.3.3",
"@ionic-native/core": "4.20.0",
"@ionic-native/network": "^4.20.0",
"@ionic-native/splash-screen": "4.20.0",
"@ionic-native/status-bar": "4.20.0",
"@ionic/angular": "^5.2.3",
"@ionic/storage": "^2.2.0",
"@ngx-translate/core": "^9.1.1",
"@ngx-translate/http-loader": "^4.0.0",
"@types/crypto-js": "^3.1.47",
"azure-blob-storage": "^4.2.4",
"chart.js": "^2.9.4",
"chartjs-subtitle": "^0.2.0",
"cordova-android": "7.1.4",
"cordova-browser": "5.0.4",
"cordova-plugin-device": "^2.0.3",
"cordova-plugin-ionic": "^5.4.7",
"cordova-plugin-ionic-keyboard": "^2.2.0",
"cordova-plugin-ionic-webview": "^4.2.1",
"cordova-plugin-splashscreen": "^5.0.4",
"cordova-plugin-statusbar": "^2.4.3",
"cordova-plugin-whitelist": "^1.3.4",
"cordova-sqlite-storage": "^5.0.0",
"crypto-js": "^4.0.0",
"file-saver": "^2.0.2",
"ionic-angular": "3.9.10",
"ionicons": "3.0.0",
"jsonwebtoken": "^8.5.1",
"passport": "^0.4.1",
"passport-jwt": "^4.0.0",
"passport-local": "^1.0.0",
"rxjs": "^6.6.6",
"rxjs-compat": "^6.6.6",
"sw-toolbox": "3.6.0",
"web": "0.0.2",
"zone.js": "0.8.29"

},

“devDependencies”: {

"@ionic/app-scripts": "^3.2.3",
"node-sass": "^4.14.1",
"typescript": "2.8.3"

},
“cordova”: {

"plugins": { 
  "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-sqlite-storage": {},
  "cordova-plugin-ionic": {
    "APP_ID": "6a5526af",
    "CHANNEL_NAME": "Production",
    "UPDATE_METHOD": "background",
    "MAX_STORE": "2",
    "MIN_BACKGROUND_DURATION": "30",
    "UPDATE_API": "https://api.ionicjs.com"
  },

  "cordova-plugin-network-information": {}
},

"platforms": [
  "android",
  "browser"
]

}

One thing that jumps out at me is the Angular 9 router in an Angular 5 project.

well spotted! thanks