Ionic-native: Ionic Native HTTP - Object(...) is not a function.

Created on 2 Jul 2019  路  2Comments  路  Source: ionic-team/ionic-native

Describe the bug
Object(...) is not a function when attempting to run app.

Complete Error Message
Error message when running in emulator, simulator, or device.

vendor.js:75624 Uncaught TypeError: Object(...) is not a function
at vendor.js:75624
at Module../node_modules/@ionic-native/http/index.js (vendor.js:75802)
at __webpack_require__ (runtime.js:84)
at Module../src/app/app.module.ts (main.js:580)
at __webpack_require__ (runtime.js:84)
at Module../src/main.ts (main.js:654)
at __webpack_require__ (runtime.js:84)
at Object.0 (main.js:676)
at __webpack_require__ (runtime.js:84)
at checkDeferredModules (runtime.js:46)

System info
Ionic:

Ionic CLI : 5.2.1 (/usr/local/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 4.6.0
@angular-devkit/build-angular : 0.13.9
@angular-devkit/schematics : 7.3.9
@angular/cli : 7.3.9
@ionic/angular-toolkit : 1.5.1

Cordova:

Cordova CLI : 9.0.0 ([email protected])
Cordova Platforms : android 8.0.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.1, (and 6 other plugins)

Utility:

cordova-res : not installed
native-run : 0.2.2 (update available: 0.2.7)

System:

Android SDK Tools : 26.1.1 (/Users/meusercx/Library/Android/sdk)
ios-deploy : 1.9.2
ios-sim : 6.1.2
NodeJS : v10.15.1 (/usr/local/bin/node)
npm : 6.9.2
OS : macOS Mojave
Xcode : Xcode 10.2.1 Build version 10E1001

Package.json:
.
.
.
"dependencies": {
"@angular/common": "^7.2.2",
"@angular/core": "^7.2.2",
"@angular/forms": "^7.2.2",
"@angular/http": "^7.2.2",
"@angular/platform-browser": "^7.2.2",
"@angular/platform-browser-dynamic": "^7.2.2",
"@angular/router": "^7.2.2",
"@ionic-native/core": "^5.0.0",
"@ionic-native/http": "^4.20.0",
"@ionic-native/splash-screen": "^5.0.0",
"@ionic-native/status-bar": "^5.0.0",
"@ionic/angular": "^4.1.0",
"cordova-android": "8.0.0",
"cordova-plugin-advanced-http": "^2.1.1",
"cordova-plugin-file": "^6.0.1",
"core-js": "^2.5.4",
"rxjs": "~6.5.1",
"tslib": "^1.9.0",
"zone.js": "~0.8.29"
},
.
.
.
"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-plugin-advanced-http": {
"OKHTTP_VERSION": "3.10.0"
}
},

Are you using ionic-native-wrapper?

Minimum viable code to reproduce
I created a blank ionic app with a single service:
import { Injectable } from '@angular/core';
import { HTTP } from '@ionic-native/http';

@Injectable({
providedIn: 'root'
})
export class TinyurlService {
constructor(private http: HTTP) { }

getTinyurl(url) {
return new Promise(resolve => {
this.http.get('https://tinyurl.com/create.php?url=' + url, {}, {})
.then(response => {
resolve(response.data)
})
.catch(error => {
console.log(error.status);
console.log(error.error); // error message as string
console.log(error.headers);
});
});
}
}

I call service from HomePage:

constructor(private tinyurlService: TinyurlService) {
this.url = tinyurlService.getTinyurl('www.google.com');
}

I setup HTTP as a provider in app module:

@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
providers: [
HTTP,
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
bootstrap: [AppComponent]
})
export class AppModule {}

Most helpful comment

@cmeuser all your @ionic-native/* packages are in version 5, except @ionic-native/http which is in version 4.
This is the cause of your issue, as you have to install @ionic-native/* packages with the same major version as your @ionic-native/core package.
Your issue should be fixed by installing the right @ionic-native/http version with:
npm i -S @ionic-native/http@5

All 2 comments

I had the same issue because I was using the latest version of http native. I uninstalled the version and reinstalled using the following commands

ionic cordova plugin add cordova-plugin-advanced-http
npm install --save @ionic-native/http@4

@cmeuser all your @ionic-native/* packages are in version 5, except @ionic-native/http which is in version 4.
This is the cause of your issue, as you have to install @ionic-native/* packages with the same major version as your @ionic-native/core package.
Your issue should be fixed by installing the right @ionic-native/http version with:
npm i -S @ionic-native/http@5

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ajcrites picture ajcrites  路  3Comments

wwallace picture wwallace  路  4Comments

mateo666 picture mateo666  路  3Comments

sabariferin picture sabariferin  路  4Comments

Manduro picture Manduro  路  3Comments