Ionic-cli: "ionic upload" and "ionic resources" don't use proxy

Created on 10 Mar 2015  路  39Comments  路  Source: ionic-team/ionic-cli

We have noticed that when we run "ionic upload" and "ionic resources" the proxy settings are ignored and the underlying https requests are made without proxy. In a usual enterprise network, this problem makes impossible to use this commands because of the security policies.

All the other commands like e.g. "ionic start" work perfectly and the download runs through the proxy with no problem. I neither have any problem with any other npm module that needs data to be downloaded from the internet.

It seems that the uploads made by ionic-cli don't use the proxy.

My system info:

OS: Windows XP
Node Version: v0.10.34
Cordova CLI: 4.2.0
Ionic CLI Version: 1.3.13

Most helpful comment

I got it working on my Windows machine. Even though I had the http_proxy and https_proxy variables set it was still erroring. To get it working, in my command prompt that I had open, I ran

  set PROXY=http://myproxyserver:serverport 
  ionic resources.

Note: If you set a system environment variable through the Environment variables GUI, make sure that you close your command prompt and re-open it. The command prompt does not pick up changes made in the GUI until you re-open it.

All 39 comments

The problem persists after updating to Ionic CLI 1.3.14

facing same issue. please let me know incase there is a solution

Looking at the ionic-cli code, it seems that the problem is produced by the npm module used to send the data to the ionic servers:

https://github.com/felixge/node-form-data

In a first look, this module doesn't have a way to configure the proxy. This library could be overriding the global proxy configuration due to the way they are doing the submit.

Not sure if another issue should be opened in their repository.

I'm having the same issue. Need to know how to add proxy settings to ionic configuration so that I can use the ionic cli upload command at work.

The problem persists after updating to Ionic CLI 1.3.17

Yes have the same issue, do we have a solution to this?

same problem here ... any fix?

same issue here...

Sorry for the late response! I'll be patching the upload command to make it work behind proxies.

I'll post when I'm done!

I don't currently have a proxy set up.

However, I've pushed a beta version.

Would some of you with proxies test it out to ensure that it works?

Ionic-CLI 1.4.4-beta.0 - npm install -g ionic@beta

I've just tested the beta you pointed and the error keeps happening. Is there any log file that I can send you with more info?

C:\ionic\test>ionic resources
Ionic icon and splash screen resources generator
V icon android drawable-ldpi-icon.png (36x36) from cache
V icon android drawable-mdpi-icon.png (48x48) from cache
V icon android drawable-hdpi-icon.png (72x72) from cache
V icon android drawable-xhdpi-icon.png (96x96) from cache
V icon android drawable-xxhdpi-icon.png (144x144) from cache
V icon android drawable-xxxhdpi-icon.png (192x192) from cache
V icon ios icon.png (57x57) from cache
V icon ios [email protected] (114x114) from cache
V icon ios icon-40.png (40x40) from cache
V icon ios [email protected] (80x80) from cache
V icon ios icon-50.png (50x50) from cache
V icon ios [email protected] (100x100) from cache
V icon ios icon-60.png (60x60) from cache
V icon ios [email protected] (120x120) from cache
V icon ios [email protected] (180x180) from cache
V icon ios icon-72.png (72x72) from cache
V icon ios [email protected] (144x144) from cache
V icon ios icon-76.png (76x76) from cache
V icon ios [email protected] (152x152) from cache
V icon ios icon-small.png (29x29) from cache
V icon ios [email protected] (58x58) from cache
V icon ios [email protected] (87x87) from cache
V splash android drawable-port-mdpi-screen.png (320x480) from cache
V splash android drawable-port-hdpi-screen.png (480x800) from cache
V splash android drawable-port-xhdpi-screen.png (720x1280) from cache
V splash android drawable-port-xxhdpi-screen.png (960x1600) from cache
V splash android drawable-port-xxxhdpi-screen.png (1280x1920) from cache
V splash ios Default-568h@2x~iphone.png (640x1136) from cache
V splash ios Default-667h.png (750x1334) from cache
V splash ios Default-736h.png (1242x2208) from cache
V splash ios Default-Portrait@2x~ipad.png (1536x2048) from cache
V splash ios Default-Portrait~ipad.png (768x1024) from cache
V splash ios Default@2x~iphone.png (640x960) from cache
V splash ios Default~iphone.png (320x480) from cache
uploading splash.psd...
? Failed to upload source image: Error: connect ETIMEDOUT

C:\ionic\test>ionic info

Your system information:

Cordova CLI: 4.3.0
Gulp version: CLI version 3.8.9
Gulp local: Local version 3.8.11
Ionic Version: 1.0.0
Ionic CLI Version: 1.4.4-beta.0
Ionic App Lib Version: 0.0.19
OS: Windows XP
Node Version: v0.10.34

It looks like your splash image is timing out. What is the file size of that image?

Just a guess here - perhaps its too large and the server is timing out?

As far as a log - let me check with the back end team to see if they have logs on it.

First of all, thanks for the work you do.

I don't think it's a timeout issue due to the file size. The splash.psd file i'ts a bit less than 1.5mb.

I think it's a proxy issue. Some weeks ago, when I opened this issue, our network admin changed the firewall to bypass the proxy for the ionic resources upload requests. After that, we noticed that the url used by the ionic cli to upload the resources changes randomly.

Since then, the upload resources command works somentimes, in fact, it works when the "ionic resources" (or "ionic upload" command) uses the url we first detected and configured in the proxy, that's to say, 1 out of 10-15 times more or less.

As an example, it has worked just a minute ago after 5 tries. (result below)

I think there is a problem with the npm module the ionic-cli uses to upload the files, https://github.com/felixge/node-form-data

C:\ionic\test>ionic resources
Ionic icon and splash screen resources generator
V icon android drawable-ldpi-icon.png (36x36) from cache
V icon android drawable-mdpi-icon.png (48x48) from cache
V icon android drawable-hdpi-icon.png (72x72) from cache
V icon android drawable-xhdpi-icon.png (96x96) from cache
V icon android drawable-xxhdpi-icon.png (144x144) from cache
V icon android drawable-xxxhdpi-icon.png (192x192) from cache
V icon ios icon.png (57x57) from cache
V icon ios [email protected] (114x114) from cache
V icon ios icon-40.png (40x40) from cache
V icon ios [email protected] (80x80) from cache
V icon ios icon-50.png (50x50) from cache
V icon ios [email protected] (100x100) from cache
V icon ios icon-60.png (60x60) from cache
V icon ios [email protected] (120x120) from cache
V icon ios [email protected] (180x180) from cache
V icon ios icon-72.png (72x72) from cache
V icon ios [email protected] (144x144) from cache
V icon ios icon-76.png (76x76) from cache
V icon ios [email protected] (152x152) from cache
V icon ios icon-small.png (29x29) from cache
V icon ios [email protected] (58x58) from cache
V icon ios [email protected] (87x87) from cache
uploading splash.psd...
V splash.psd (2208x2208) upload complete
generating splash ios Default~iphone.png (320x480)...
generating splash ios Default@2x~iphone.png (640x960)...
generating splash ios Default-Portrait~ipad.png (768x1024)...
V splash ios Default~iphone.png (320x480) generated
generating splash ios Default-Portrait@2x~ipad.png (1536x2048)...
V splash ios Default@2x~iphone.png (640x960) generated
generating splash ios Default-736h.png (1242x2208)...
V splash ios Default-Portrait~ipad.png (768x1024) generated
generating splash ios Default-667h.png (750x1334)...
V splash ios Default-736h.png (1242x2208) generated
generating splash ios Default-568h@2x~iphone.png (640x1136)...
V splash ios Default-Portrait@2x~ipad.png (1536x2048) generated
generating splash android drawable-port-xxxhdpi-screen.png (1280x1920)...
V splash ios Default-667h.png (750x1334) generated
generating splash android drawable-port-xxhdpi-screen.png (960x1600)...
V splash ios Default-568h@2x~iphone.png (640x1136) generated
generating splash android drawable-port-xhdpi-screen.png (720x1280)...
V splash android drawable-port-xxhdpi-screen.png (960x1600) generated
generating splash android drawable-port-hdpi-screen.png (480x800)...
V splash android drawable-port-xxxhdpi-screen.png (1280x1920) generated
V splash android drawable-port-mdpi-screen.png (320x480) generated
generating splash android drawable-port-ldpi-screen.png (240x320)...
V splash android drawable-port-xhdpi-screen.png (720x1280) generated
V splash android drawable-port-ldpi-screen.png (240x320) generated
V splash android drawable-port-hdpi-screen.png (480x800) generated

Hello . Is the new version of upload.js that fixes the problem of using ionic upload behind proxy has been integrated(https://github.com/driftyco/ionic-cli/blob/master/lib/ionic/upload.js?MobileOptOut=1) ?

Because i still have the problem on the latest release :
Ionic cli version : 1.4.6
Ionic app lib version : 0.0.22

I got "Error connect : ETIMEDOUT"

thank you very much

@jbavari , any update on this issue ? any workaround to this ...it is impossible to upload project built in enterprise environment.

Workaround: Open '_npm_folder_node_modules\ionic\lib\ionicresources\generate.js' and replace all 'process.env.PROXY' with your proxy settings like 'http://myproxy:myport'.
Worked for me ;-)

@RobertLibe , i am not getting ionic folder inside node_modules directory in my project..
I am using ionic version 1.0.0 (uranium-unicorn)

You have to change it globally: So the folder on Windows is mostly

C:\Users\USER\AppData\Roaming\npm\node_modules\ionic\lib\ionic\resources
set PROXY=http://LOGIN:USER@URL:PORT
ionic resources android --icon --force

Work fine, this issue must be close
Ami44

Worked in my Mac as:
$ PROXY=http://LOGIN:USER@URL:PORT ionic start myApp sidemenu

Yes, this is working for mac, but not for Windows. Tried to set environment variable PROXY without success.

+1

Your system information:

Cordova CLI: 5.1.1
Ionic Version: 1.0.1
Ionic CLI Version: 1.6.1
Ionic App Lib Version: 0.3.3
OS: Windows 8.1
Node Version: v0.12.5

I got it working on my Windows machine. Even though I had the http_proxy and https_proxy variables set it was still erroring. To get it working, in my command prompt that I had open, I ran

  set PROXY=http://myproxyserver:serverport 
  ionic resources.

Note: If you set a system environment variable through the Environment variables GUI, make sure that you close your command prompt and re-open it. The command prompt does not pick up changes made in the GUI until you re-open it.

Hi,

I'm currently on Windows and tried the different workarounds proposed here.
Here's the stack trace when trying to upload behind the company proxy:

$ ionic upload
Uploading app....
There was an error trying to upload your app.
C:\Users\PSKA09831\AppData\Roaming\npm\node_modules\ionic\node_modules\ionic-app-lib\lib\upload.js:276
    response.setEncoding('utf8');
            ^

TypeError: Cannot read property 'setEncoding' of undefined
    at ClientRequest.<anonymous> (C:\Users\PSKA09831\AppData\Roaming\npm\node_modules\ionic\node_modules\ionic-app-lib\lib\upload.js:276:13)
    at emitOne (events.js:77:13)
    at ClientRequest.emit (events.js:169:7)
    at TLSSocket.socketErrorListener (_http_client.js:265:9)
    at emitOne (events.js:77:13)
    at TLSSocket.emit (events.js:169:7)
    at emitErrorNT (net.js:1256:8)
    at nextTickCallbackWith2Args (node.js:455:9)
    at process._tickCallback (node.js:369:17)

The Form Data module seems to be the reason..
Any help would be appreciated.

Thank you

My environement info. might be helpful:

Cordova CLI: 5.4.1
Gulp version: CLI version 3.9.0
Gulp local: Local version 3.9.0
Ionic Version: 1.1.0
Ionic CLI Version: 1.7.12
Ionic App Lib Version: 0.6.5
OS: Windows 7 SP1
Node Version: v5.3.0

I am facing exactly same issue as @skokaina

I have added proxy. The first error of upload gone but facing issues at "setEncoding".

Same issue here, the reason is that response is undefined because of "Error: connect ETIMEDOUT 104.20.6.16:443"

I have fixed this issue locally and created a Pull Request.

After installing https-proxy-agent, your fix works for me !
Thanks @rpinto

$ PROXY=http://<login>:<user>@<user>:<port> ionic resources was the fix for me on Ubuntu 14.04, although the proxy environmental variable was set yet before.(notice the case here)

Your system information:

Cordova CLI: 5.4.1
Gulp version:  CLI version 3.9.0
Gulp local:   Local version 3.9.1
Ionic CLI Version: 1.7.12
Ionic App Lib Version: 0.6.5
OS: Distributor ID: Ubuntu Description: Ubuntu 14.04.3 LTS 
Node Version: v4.1.2

I have found this related PR: https://github.com/form-data/form-data/pull/179

Ok, it looks like I have something working on my side without having to modify form-data:

https://gist.github.com/mably/ffb351f4e4cd0867ee5d86462e266b6f

Any feedback welcome.

EDIT: Ok, looks like a simpler fix has been published in a previous comment, sorry for the annoyance.

@digitaldrummerj it works for me.

This continues to be a problem for me as well with the 'ionic package' command. There is a viable solution in a PR here that could be applied across the affected ionic cli commands:
https://github.com/driftyco/ionic-app-lib/pull/58

Please either allow this fix through or help persuade the FormData folks to let this other one through that solves it on their end:
https://github.com/form-data/form-data/pull/179

We are running this through jenkins on an EC2 linux instance behind a proxy. And get the same FormData error as others:

15:21:48 + ionic package build android
15:23:57 /var/lib/jenkins/.nvm/versions/node/v4.4.3/lib/node_modules/ionic/node_modules/ionic-app-lib/lib/upload.js:276
15:23:57 response.setEncoding('utf8');
15:23:57 ^
15:23:57
15:23:57 TypeError: Cannot read property 'setEncoding' of undefined
15:23:57 at ClientRequest. (/var/lib/jenkins/.nvm/versions/node/v4.4.3/lib/node_modules/ionic/node_modules/ionic-app-lib/lib/upload.js:276:13)
15:23:57 at emitOne (events.js:77:13)
15:23:57 at ClientRequest.emit (events.js:169:7)
15:23:57 at TLSSocket.socketErrorListener (_http_client.js:256:9)
15:23:57 at emitOne (events.js:77:13)
15:23:57 at TLSSocket.emit (events.js:169:7)
15:23:57 at emitErrorNT (net.js:1253:8)
15:23:57 at nextTickCallbackWith2Args (node.js:442:9)
15:23:57 at process._tickCallback (node.js:356:17)

Same issue here with most recent ionic@beta build. Node/NPM working fine with globally set Proxy config.

Your system information:

Cordova CLI: 6.1.1
Gulp version:  CLI version 3.9.1
Gulp local:   Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.6
Ionic CLI Version: 2.0.0-beta.25
Ionic App Lib Version: 2.0.0-beta.15
OS: Distributor ID:     Ubuntu Description:     Ubuntu 14.04.4 LTS
Node Version: v4.4.4

Error while uploading: 

Uploading app....
There was an error trying to upload your app.
Caught exception:
 TypeError: Cannot read property 'setEncoding' of undefined

This is a major annoyance for your corporate clients :(

Still an issue :(

Cordova CLI: 6.2.0
Gulp version:  CLI version 1.2.1
Gulp local:   Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.10
Ionic CLI Version: 2.0.0-beta.32
Ionic App Lib Version: 2.0.0-beta.18
OS: Windows 7 SP1
Node Version: v5.11.1

@mably: I have found this related PR: form-data/form-data#179
This one worked for me. My version of ionic: 1.7.16.

Closing this as a duplicate of #692

This fix work for me ( see my comment in this PR)
https://github.com/driftyco/ionic-app-lib/pull/58

Was this page helpful?
0 / 5 - 0 ratings