Ionic 4.12 - Running on device gives me CORS error. It ignores proxy config. How to overcome this?


I want to run the app on my device but it gives me hard time: (ionic 4.12).
Running on device gives me CORS error and ignores proxy server config.

It run on localhost:8080 not file:// ? (I test the location at the console of Remote Devices)


1 Like

I would need more context to debug. What are your API URLs located at?

Hi 10x for the reply:

It doesn’t matter which api. you can call “”.

The problem is that when running on android deivice it turns the webview into localhost:8080 instead of file://.

So how do i debug it?

Below link should help.

Change your address from http://localhost:8080 to http://IP_Address:Server Port Number.

Thanks but does not work

10x but this I can’t do because this is how ionic run works on device.

It seems the proxy does not work on running in device

Since I don’t have much information on your ionic version, android platform etc, all I can help you with is links. Look at below links:

Guys. This is ridiculous. I’ve just spent an hour dredging through Stack Overflow and this forum. As far as I can tell, NOBODY knows how to get Proxies to work for Ionic 4. Can someone from ionic maybe put together a demo app with the right stuff in it and post it somewhere. Thousands of hours are being wasted swearing, that should be spent telling other people how great ionic is…

Personally, I’m trying to use the angular httpClient. I want to create a mobile app and a PWA in the end. I like the way httpClient uses observables. So, I spent about a day or 2, tearing out all the native ionic http stuff. According to at least 50% of the opinionated masses (yes the other 50% were on the fence), this is the right thing to do, for more reasons that I care to elaborate here. However, you know where this is going… I get a CORS error on my device when I run devApp or ionic run, so I can’t debug on the device. And I have no idea if it will work when built in the end. Since my app is in tatters right now, I just don’t have the energy to try.

So, adding proxies to your ionic.config.json doesn’t work.
Creating a proxy.conf.json file which holds a target doesn’t work, no matter whether you point to it from within your angular.json, or you add it explicitly to the command when you run the serve.

So I’m left with no option but to go back to using the native http and sucking up all the above (not actually) mentioned negatives.


I’ve gone back to

import { Http, Headers, Response } from ‘@angular/http’;

and CORS errors vanishes. I have no idea why, nor do I want to. Perhaps soetime in 2023 when someone has figured out how to get httpClient to work, I’ll upgrade again.

1 Like

That didn’t work.

CORS on device just does not work. Because the angular proxy is not activated like on running on browser for some reason

This is not a solution for me.

I need to use external library to do my calls.

what the hell ionic 4 did?

at 2 it was much simpler