ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
51.07k stars 13.51k forks source link

[ionic4] HTTP ionic native JS error (@ionic-native/http) #15199

Closed bibounet closed 6 years ago

bibounet commented 6 years ago

Bug Report

Ionic Info

Ionic:

   ionic (Ionic CLI)          : 4.0.6 (C:\Users\toto\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework            : @ionic/angular 4.0.0-beta.2
   @angular-devkit/core       : 0.7.3
   @angular-devkit/schematics : 0.7.3
   @angular/cli               : 6.1.3
   @ionic/ng-toolkit          : 1.0.6
   @ionic/schematics-angular  : 1.0.4

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : android 7.0.0

System:

   NodeJS : v8.9.4 (C:\Program Files\nodejs\node.exe)
   npm    : 5.6.0
   OS     : Windows 10

Describe the Bug One adding HTTP ionic native to an ionic4 project it crash at android app lauch, HTTP ionic native module throw an JS error :

index.js:518 Uncaught TypeError: Object(...) is not a function
    at index.js:518
    at Object../node_modules/@ionic-native/http/index.js (index.js:702)
    at __webpack_require__ (bootstrap:81)
    at Object../src/app/app.module.ts (app.component.ts:11)
    at __webpack_require__ (bootstrap:81)
    at Object../src/main.ts (environment.ts:15)
    at __webpack_require__ (bootstrap:81)
    at Object.0 (main.ts:12)
    at __webpack_require__ (bootstrap:81)
    at checkDeferredModules (bootstrap:43)
l513:    };
l514:    HTTP.decorators = [
l515:        { type: Injectable },
l516:    ];
l517:    __decorate([
l518:        Cordova({ sync: true }), // <----------------------------------
l519:        __metadata("design:type", Function),
l520:        __metadata("design:paramtypes", [String, String]),
l521:        __metadata("design:returntype", Object)
l522:    ], HTTP.prototype, "getBasicAuthHeader", null);

Steps to Reproduce

  1. start ionic4 project
  2. ionic cordova platform add android
  3. ionic cordova plugin add cordova-plugin-advanced-http
  4. npm install --save @ionic-native/http
  5. Add HTTP plugin to your app's module
  6. constructor(private http: HTTP) {}
    
    public getHtmlTest(url: string): void {
            this.http.get(url, {}, {})
                .then(data => {
                    console.log(data.status);
                    console.log(data.data); // data received by server
                    console.log(data.headers);
                })
                .catch(error => {
                    console.log(error.status);
                    console.log(error.error); // error message as string
                    console.log(error.headers);
                });
    }
Alex1000A commented 6 years ago

Hi solution on here

https://github.com/ionic-team/ionic/issues/14781

bibounet commented 6 years ago

Thanks a lot! it works for me now :

ionitron-bot[bot] commented 6 years ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.