Wednesday, September 3, 2014

npm - first encounters

Playing with node.js at work I hit an issue in the very beginning as I was unable to install any package using npm (the convenient package manager of node).

$ npm install nodemon
npm ERR! network tunneling socket could not be established, cause=connect EINVAL
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network 
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

Ok, I really use a proxy so I run npm config edit and uncomment these lines:

; proxy=proxy:8080
; https-proxy=proxy:8080

Same result

$ npm install nodemon
npm ERR! network tunneling socket could not be established, 

The error EINVAL suggests that connect was called with an invalid argument. What that might be? Let's see the system calls of npm:

$ strace npm install nodemon 1> npm.strace 2>&1
$ grep EINVAL npm.strace
ioctl(9, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7fff5f9a8330) = -1 EINVAL (Invalid argument)
connect(10, {sa_family=AF_INET, sin_port=htons(443), sin_addr=inet_addr("0.0.31.144")}, 16) = -1 EINVAL (Invalid argument)
connect(10, {sa_family=AF_INET, sin_port=htons(443), sin_addr=inet_addr("0.0.31.144")}, 16) = -1 EINVAL (Invalid argument)
connect(10, {sa_family=AF_INET, sin_port=htons(443), sin_addr=inet_addr("0.0.31.144")}, 16) = -1 EINVAL (Invalid argument)
write(2, " tunneling socket could not be e"..., 65 tunneling socket could not be established, cause=connect EINVAL

Ahaa, we see 3 calls to connect with IP 0.0.31.144 and port 443 (default HTTPS port) and all of these returned EINVAL (Invalid argument).
What is this strange IP? Asking Google for it, revealed this post according to which, environment variable http_proxy should be given with a protocol, e.g.

http_proxy=http://proxy:8080

So setting https-proxy=http://proxy:8080 in npm config did solve the problem!

On my Linux both of these are set:

https_proxy=http://proxy:8080
HTTPS_PROXY=proxy:8080

and it seems npm takes the upper case variable to set the default values in npm config.

No comments:

Post a Comment