Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yarn ignores no_proxy environment variable when proxy property set #5048

Open
KimTaehee opened this issue Dec 6, 2017 · 32 comments
Open

Yarn ignores no_proxy environment variable when proxy property set #5048

KimTaehee opened this issue Dec 6, 2017 · 32 comments

Comments

@KimTaehee
Copy link

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

@ghost ghost assigned rally25rs Dec 6, 2017
@ghost ghost added the triaged label Dec 6, 2017
@rally25rs
Copy link
Contributor

rally25rs commented Dec 6, 2017

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 request/request#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.

@KimTaehee
Copy link
Author

KimTaehee commented Dec 7, 2017

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 #1564 did.
Or small notice about above workaround can help users.

@wvandeneede
Copy link

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

@rally25rs
Copy link
Contributor

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

@glausmichael
Copy link

Please review my pull request to add no-proxy support for config file: #5757

@ghost
Copy link

ghost commented Nov 29, 2018

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...

@glausmichael
Copy link

glausmichael commented Nov 30, 2018 via email

@raghukiranp
Copy link

raghukiranp commented Dec 12, 2018

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.

@paztis
Copy link

paztis commented Mar 12, 2019

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 request/request#3122) that will simplify the PR.

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

@paztis
Copy link

paztis commented May 7, 2019

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.

@ThePlenkov
Copy link

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.

@AntonyCanut
Copy link

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 ?

@paztis
Copy link

paztis commented Dec 30, 2019

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

@paztis
Copy link

paztis commented Dec 30, 2019

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.

@Trakhan
Copy link

Trakhan commented Mar 6, 2020

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

@jk195417
Copy link

jk195417 commented Mar 26, 2020

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 🎉

@paztis
Copy link

paztis commented Mar 26, 2020

Woaw this is tricky. Will try it asap

@wvandeneede
Copy link

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

@walter-heestermans-toyota

Did the above trick solved the issue?

@moonkev
Copy link

moonkev commented Jun 26, 2020

@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

@fjakop
Copy link

fjakop commented Sep 17, 2020

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

@paztis
Copy link

paztis commented Nov 16, 2020

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.

@xunchangguo
Copy link

how to solve this issue?

@dnperfors
Copy link

  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.

@paztis
Copy link

paztis commented Feb 2, 2021

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

@grosch-intl
Copy link

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

@paztis
Copy link

paztis commented Mar 2, 2022

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

@vasuneet
Copy link

vasuneet commented Jul 1, 2022

Do we have update on this ?

@grosch-intl
Copy link

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?

@erict-square
Copy link

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

@silviuburceadev
Copy link

@erict-square It worked for me :)

@cristiand391
Copy link

cristiand391 commented Nov 8, 2023

hi folks 👋🏼

based on this workaround, has anyone tried passing --no-default-rc to yarn <install | add> to make it ignore the yarn/npm config file and pass proxy configs via the npm_config env var? I'm curious if yarn would read stuff from npm_config as if they were env vars or yarn configs.

Screenshot 2023-11-08 at 15 57 21

https://classic.yarnpkg.com/en/docs/envvars#toc-npm-config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests