gund / ng-http-interceptor

Http Interceptor library for Angular
MIT License
104 stars 16 forks source link

[Ionic 2] Runtime error in constructor #75

Closed 6utt3rfly closed 7 years ago

6utt3rfly commented 7 years ago

I'm just trying to import this into an ionic 2 rc-4 app. I npm installed this and proxy-polyfill. If I include HttpInterceptorService in either my class constructor (and don't even use it), or if I add it to @NgModule.imports, then I get a runtime error when the app starts:


Cannot convert undefined or null to object
Stack
TypeError: Cannot convert undefined or null to object
    at hasOwnProperty (<anonymous>)
    at Function.__webpack_require__.o (http://localhost:8100/build/main.js:60:103)
    at Object.<anonymous> (http://localhost:8100/build/main.js:253049:67)
    at __webpack_require__ (http://localhost:8100/build/main.js:20:30)
    at Object.<anonymous> (http://localhost:8100/build/main.js:253127:70)
    at __webpack_require__ (http://localhost:8100/build/main.js:20:30)
    at Object.<anonymous> (http://localhost:8100/build/main.js:124508:79)
    at __webpack_require__ (http://localhost:8100/build/main.js:20:30)
    at Object.<anonymous> (http://localhost:8100/build/main.js:187013:95)
    at __webpack_require__ (http://localhost:8100/build/main.js:20:30)
Ionic Framework: 2.0.0-rc.4
Ionic Native: 2.2.12
Ionic App Scripts: 0.0.48
Angular Core: 2.2.1
Angular Compiler CLI: 2.2.1
Node: 6.8.1
OS Platform: OS X El Capitan
Navigator Platform: MacIntel
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36```
gund commented 7 years ago

Hi, thanks for reporting an issue.

First what comes into my mind is version mismatch, you should be using angular v2.3.0 or higher. Please try to update and run again.

And also can you tell which version you are trying to use (cause as far as I know Ionic using AOT and this library got AOT support only since v1.0.0)

Thanks

6utt3rfly commented 7 years ago

Unfortunately, Ionic requires specific angular versions, so I can't update to v2.3.0 or higher. Thank you for your quick response though!

gund commented 7 years ago

Well maybe you can at least try to load lib without proxy polyfill (if a web view supports it natively of course) so we can have better understanding which part is failing?

6utt3rfly commented 7 years ago

I was able to switch to angular2-interceptors, but it is less versatile and more restrictive where my interceptors have to be careful not to use Http to avoid cyclic dependencies. I think I'll still need proxy polyfill in order to support a wider range of mobile devices. But I'll see if I can dig a bit deeper to see where it's failing...

6utt3rfly commented 7 years ago

Error is coming from:

__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };

where 'object' is undefined and 'property' is HttpInterceptorService

gund commented 7 years ago

Unfortunately this piece of code does not tell me anything since it is generated and I guess not by ngc but by ionic itself which I haven't tried yet.

Maybe I will try to create some simple Ionic app and import lib there to get better understanding what might happen there.

gund commented 7 years ago

Hi @Emmpa.

I was able to test it in Ionic 2 and I found some weird code generation from Webpack which was trying to access import before it was actually resolved. So the first fix which crossed my mind is to rearrange exports and I did it - and it fixed the issue =)

I also verified some basic interceptions for requests/responses to make sure everything works well - and it is.

So will push a fix in a while, please do verify that it fixes the issue on your side as well and if not go ahead and reopen this one.

Thanks

gund commented 7 years ago

Fix landed in v1.3.1

6utt3rfly commented 7 years ago

Hi @gund ! Thank you for looking into this! It looks like your change has resolved my issue (and I had to do something minor when it complained about undefined "__extends"), but I can use your module now! Thank you!!

gund commented 7 years ago

Good to know that it works =) Regarding your minor issue you can have a look at #89.