NPM package installation behind a proxy
While installing yo
behind proxy you may get issues as described in this issue
The root cause is that yo
is trying to connect to the internet while doing the sanity checks on your system using a global proxy as described here and there
I was not able to change the GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE
from undefined
to an empty variable from the powershell, so I edited the node_modules\got\index.js:requestAsEventEmitter(opts):~22
and added the following line
process.env.GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE="";
Watch Out:
ping
ing the desired address and failing doesn't mean the address is not accessible, it could be very misleading while debugging, but it could be the case that ICMP didn't work for the npm registry.curl
ing should work anyway, also due to the fact that npm registry exists behind cloudflare it is not possible to access through the browser using the IP address, and one needs to usehttps://registry.npmjs.org/
directly.
Global agent
Edit: By adding the environment variable GLOBAL_AGENT_HTTPS_PROXY
set to the PROXY_URL:PROXY_PORT, alongside with the correct NO_PROXY
environment variable, for example: localhost,127.0.0.1,10.0.0.0/8,172.0.0.1/12,192.168.0.0/16
the proxy shall work.
Note: In case npm took too much time, like for yo, one needs also to disable the update-notifier
by using npm config set update-notifier false
yo
uses global-agent
which is problematic even with it's interesting concept of masking the proxy to allow having multiple proxy profiles settings per environment each in a different namespace
The problems are:
- More points of HTTP proxy setting, further debugging for points of failures for the proxy
- Behavior differs based on the difference between the following values of
GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE
:undefined
: use aGLOBAL_
prefixed http_proxy- empty: use the original
HTTP_PROXY
,HTTPS_PROXY
andNO_PROXY
env vars
- Issues show up on different modules with no further hints, which gives interesting side-effects if the modules were not explicit about using this package underhood and theri configurability based on this package's usage, for example,
yo-doctor
showed it while usinggot
, which internally usesglobal-agent
- Under Windows, it's impossible to set an empty environment variable
Even when using the command
reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment" /v GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE /d ""
provided in the SO Answer, the env variable would show up in the system env vars, but it would not be retrievable bypowershell
,cmd
, nor even nodejs would catch it.
ESLint
I had some issue with eslint due to a difference in ecmascript version than the one that the code is installed on, that's when I had to update the eslint config file, which is something like that
- A useful eslint guide