yarn
yarn copied to clipboard
Yarn ignores no_proxy environment variable when proxy property set
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.
- Set
proxy
andhttps-proxy
config and can find fromyarn config list
...
info npm config
{ proxy: 'http://some.proxy.host:8080/',
'https-proxy': 'http://some.proxy.host:8080/',
...
- Set
NO_PROXY
orno_proxy
environment variable like$ no_proxy="some.url.private.repo"
- Run
yarn install
-
proxy
andhttps-proxy
work butno_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
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.
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.
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?
tagging this as a feature request to add a no-proxy
config setting. Anyone want to put together a PR for this?
Please review my pull request to add no-proxy support for config file: https://github.com/yarnpkg/yarn/pull/5757
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...
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)
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.
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...
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.
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.
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 ?
My PR is for one of the yarn dependencies (request). Until it is approved, nothing can be done in yarn :-(
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.
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
I found a workaround if you need to connect to private npm registry by config proxy and you have yarn
and npm
both install
- 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
- Setup
.npmrc
https-proxy=http://proxy.company.com:80/
proxy=http://proxy.company.com:80/
no-proxy=.company.com
- Setup
.yarnrc
https-proxy ""
proxy ""
There is the trick
- Yarn will use proxy setting from
.npmrc
- If yarn have
proxy
andhttps-proxy
config,request
lib will using it but ignoreno-proxy
- If yarn don't have
proxy
andhttps-proxy
config,request
lib will using system environment variable
Then both your yarn
and npm
works 🎉
Woaw this is tricky. Will try it asap
The problem with setting PROXY and NO_PROXY env variables is that other tools, like for example Visual Studio, also pick these up.
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
Looks like a great opportinity to support no-proxy
in .yarnrc, same issue for me.
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.
how to solve this issue?
- 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.
But in case of no environment car at all, any solution ?
5 years later...any chance this issue will get resolved?
My requests or has been approved 2 days ago but still not merged. Now with yarn 3 this issue is a bit less useful
Do we have update on this ?
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?
Do we know if @jk195417's workaround still works now?