yarn icon indicating copy to clipboard operation
yarn copied to clipboard

Yarn ignores no_proxy environment variable when proxy property set

Open KimTaehee opened this issue 7 years ago • 33 comments

Do you want to request a feature or report a bug? Both

What is the current behavior? If proxy and http-proxy are set, NO_PROXY and no_proxy environment variables are ignored.

If the current behavior is a bug, please provide the steps to reproduce.

  1. Set proxy and https-proxy config and can find from yarn config list
...
info npm config
{ proxy: 'http://some.proxy.host:8080/',
  'https-proxy': 'http://some.proxy.host:8080/',
...
  1. Set NO_PROXY or no_proxy environment variable like $ no_proxy="some.url.private.repo"
  2. Run yarn install
  3. proxy and https-proxy work but no_proxy environment variable is ignored.

What is the expected behavior? NO_PROXY or no_proxy environment variable is applied.

Please mention your node.js, yarn and operating system version. Ubuntu 16.04 yarn 1.3.2

KimTaehee avatar Dec 06 '17 01:12 KimTaehee

Yes. This happens because the env vars HTTP_PROXY, HTTPS_PROXY, NO_PROXY are handled by the Request library.

However, request ignores the env vars if a proxy is passed to it. Yarn finds a proxy in its config and sends it to request which causes it to ignore the NO_PROXY env var.

There is some discussion of this behavior here https://github.com/request/request/pull/1195 and it looks like NPM tackled the same issue at some point.

A workaround would be to set your proxies as env vars instead of in yarn config.

rally25rs avatar Dec 06 '17 16:12 rally25rs

Thanks for your answer.
But it's weird to users and They can expect no_proxy env var works. I think argument like --no-proxy <hosts> can solve this problem. As https://github.com/yarnpkg/yarn/pull/1564/ did.
Or small notice about above workaround can help users.

KimTaehee avatar Dec 07 '17 05:12 KimTaehee

npm (5.8.0-next.0) just merged the no-proxy setting in .npmrc: https://github.com/npm/npm/pull/19157 Something similar possible with yarn?

wvandeneede avatar Mar 23 '18 14:03 wvandeneede

tagging this as a feature request to add a no-proxy config setting. Anyone want to put together a PR for this?

rally25rs avatar Mar 25 '18 23:03 rally25rs

Please review my pull request to add no-proxy support for config file: https://github.com/yarnpkg/yarn/pull/5757

glausmichael avatar Apr 30 '18 11:04 glausmichael

What is the status of this feature? I have CI/CD that has to use proxy to communicate with cluster and yarn is blocking me since it fails to install packages. Edit: found a workaround from comments on PR to this issue to be acceptable. My blocker is now npm package that doesn't repects no_proxy env...

ghost avatar Nov 29 '18 15:11 ghost

The reviewer seems to have another understanding of the problem. For us, we solved it by removing proxy settings from .yarnrc file but providing them with environment variables only instead. (HTTP_PROXY, HTTPS_PROXY, no_proxy)

glausmichael avatar Nov 30 '18 20:11 glausmichael

Hello,

Our organization blocks the intranet url requests through proxy. It is mandatory for us to use no_proxy or proxy bypass options in browser and console to get intranet url's working.

In our case, we are hosting an internal registry and I need to download some packages from internet using proxy and some from internet as needed.

When I set proxy in yarn config, requests to our internal registries are blocked and if I remove proxy settings, I can't download other yarn packages from internet.

Any help / pointers / workaround is appreciated.

EDIT: as suggested in the above comment by rally25rs, removing proxy settings from yarn config and having them in shell helped.

raghukiranp avatar Dec 12 '18 10:12 raghukiranp

On my company side, as we work with multiple projects in same time, it is forbidden to play with global env var. Everything must be under the project folder. And with all the spawn in our scripts it start to became crazy to all the time reset local env var that works on windows and on Linux. Npm is supporting it but I still need yarn for the workspaces support.

The glaussmickael seems to cover the need. Or if you prefer an official solution you can ask to request to support the option (see this discussion https://github.com/request/request/issues/3122) that will simplify the PR.

In current state it is not possible to yarn to be compatible with npm...

paztis avatar Mar 12 '19 02:03 paztis

I've created a PR for request that will add the support of noProxy option here. If this PR is accepted it means yarn can easily read the no-proxy field in the .npmrc and always pass it, as it do for the proxy and https-proxy fields.

paztis avatar May 07 '19 11:05 paztis

This is an exact reason why I cannot use yarn in my working environment. Some of modules I need to take from the external resources - some from internal. Only by disabling proxy settings for specific domains I can resolve my issue in yarn. Really - npm is not that bad in this case.

ThePlenkov avatar Dec 24 '19 10:12 ThePlenkov

Hello, I need noproxy for my teams. I think to replace actual yarn by your PR (@paztis).

Any option to avoid that ? Maybe accelerate review/acceptation ?

AntonyCanut avatar Dec 30 '19 16:12 AntonyCanut

My PR is for one of the yarn dependencies (request). Until it is approved, nothing can be done in yarn :-(

paztis avatar Dec 30 '19 17:12 paztis

Request lib seems in maintenance only mode. No new enhancement will be accepted... Yarn need to process itself the address to pass or not the proxy option to request. I don't know if yarn v2 will still have a dependency to request or not.

paztis avatar Dec 30 '19 18:12 paztis

As environment variables do not work anymore (since yarn 1.9), I was forced to come up with different workaround.

On unix based system (I used alpine in docker), one can utilize proxychains-ng to handle proxies outside of yarn altogether.

Very simplified proxyconfig.conf:

strict_chain
#proxy_dns <<I didn't want this, as my addresses are local
remote_dns_subnet 224
tcp_read_time_out 15000
tcp_connect_time_out 8000

# By default enable localnet for loopback address ranges
# RFC5735 Loopback address range
localnet 127.0.0.0/255.0.0.0

#Bypass proxy subnet/Ip address
localnet XXX.XXX.XXX.XXX/255.255.255.0

[ProxyList]
# proxy outside
http XXX.XXX.XXX.XXX 8080

Then run yarn with this command (argument -q is important - does not work without it): proxychains -q yarn install

Trakhan avatar Mar 06 '20 18:03 Trakhan

I found a workaround if you need to connect to private npm registry by config proxy and you have yarn and npm both install

  1. Setup system environment variable
PROXY=http://proxy.company.com:80
NO_PROXY=".company.com"
export PROXY=$PROXY
export HTTP_PROXY=$PROXY
export HTTPS_PROXY=$PROXY
export NO_PROXY=$NO_PROXY
  1. Setup .npmrc
https-proxy=http://proxy.company.com:80/
proxy=http://proxy.company.com:80/
no-proxy=.company.com
  1. Setup .yarnrc
https-proxy ""
proxy ""

There is the trick

  • Yarn will use proxy setting from .npmrc
  • If yarn have proxy and https-proxy config, request lib will using it but ignore no-proxy
  • If yarn don't have proxy and https-proxy config, request lib will using system environment variable

Then both your yarn and npm works 🎉

jk195417 avatar Mar 26 '20 01:03 jk195417

Woaw this is tricky. Will try it asap

paztis avatar Mar 26 '20 06:03 paztis

The problem with setting PROXY and NO_PROXY env variables is that other tools, like for example Visual Studio, also pick these up.

wvandeneede avatar Mar 26 '20 07:03 wvandeneede

Did the above trick solved the issue?

@walter-heestermans-toyota I can confirm this setup worked for me. I had the exact same scenario - behind a corporate proxy, but needed to access an internal registry (nexus) Thanks a lot @jk195417

moonkev avatar Jun 26 '20 20:06 moonkev

Looks like a great opportinity to support no-proxy in .yarnrc, same issue for me.

fjakop avatar Sep 17 '20 12:09 fjakop

one question: there's still my PR open in request package, that is unmaintained now. If I publish my fork of it, with only the change I create, will yarn team be agree to switch to my version ?

IN this case noProxy option can be officially supported. It starts to be important now because NPM is accepting it AND npm is also supporting the monorepo now.

paztis avatar Nov 16 '20 08:11 paztis

how to solve this issue?

xunchangguo avatar Nov 25 '20 09:11 xunchangguo

  1. Setup .yarnrc
https-proxy ""
proxy ""

Another way of doing this is to export the following environment variables:

export YARN_PROXY=""
export YARN_HTTPS_PROXY=""

This works very well in build pipelines where HTTP_PROXY, HTTPS_PROXY and NO_PROXY are set by default.

dnperfors avatar Feb 02 '21 13:02 dnperfors

But in case of no environment car at all, any solution ?

paztis avatar Feb 02 '21 17:02 paztis

5 years later...any chance this issue will get resolved?

grosch-intl avatar Mar 02 '22 20:03 grosch-intl

My requests or has been approved 2 days ago but still not merged. Now with yarn 3 this issue is a bit less useful

paztis avatar Mar 02 '22 20:03 paztis

Do we have update on this ?

vasuneet avatar Jul 01 '22 20:07 vasuneet

My requests or has been approved 2 days ago but still not merged. Now with yarn 3 this issue is a bit less useful

@paztis What do you mean by that?

grosch-intl avatar Jul 05 '22 21:07 grosch-intl

Do we know if @jk195417's workaround still works now?

erict-square avatar Aug 03 '22 00:08 erict-square