frontend-maven-plugin
frontend-maven-plugin copied to clipboard
Non-Proxy hosts with wildcards are incorrectly passed to npm
Steps to reproduce
- Configure a maven proxy with a wildcard non proxy hosts, e.g.
*.google.de(see DefaultNpmRunnerTest.java)
Expected result
- npm is called with
--noproxy=*.google.de
Actual result
- npm is called with
--noproxy=.google.de. The asterisk is missing. ~~npm does not understand this syntax.~~
Analysis
- in https://github.com/eirslett/frontend-maven-plugin/blame/b7b060fa13ca47e69172ee6d06194ffd41c35084/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NpmRunner.java#L39 , asterisks are deliberately removed
@tkalmar do you remember any of this?
short test:
npm config set https-proxy https://proxy.example.com:1337
npm show lodash --registry=https://registry.npmjs.org/ <-- timeout
npm show lodash --registry=https://registry.npmjs.org/ --noproxy=.npmjs.org <-- works
npm show lodash --registry=https://registry.npmjs.org/ --noproxy=*.npmjs.org <-- timeout
so i can't confirm that npm does not understand this syntax
Thank you for your swift response, @eirslett and @tkalmar. I missed a piece of the puzzle. The error occurred when running npm install. Our package.json contains a dependency with explicit git hostname like:
{
"devDependencies": {
"privateLib": "git+https://git.corp.network/privateLib.git#main"
}
}
Error message was:
[INFO] Found proxies: [httpsproxy{protocol='https', host='proxy.corp.network', port=8080, nonProxyHosts='*.corp.network'}]
[INFO] npm error code 128
[INFO] npm error An unknown git error occurred
[INFO] npm error command git --no-replace-objects ls-remote https://git.corp.network/privateLib.git
[INFO] npm error fatal: unable to access 'https://git.corp.network/privateLib.git': Received HTTP code 503 from proxy after CONNECT
~~I had to explicitly add git.corp.network to the maven non-proxy hosts to make this work.~~ (Note from the future: It did not fix it)
I tried calling npm install --noproxy=*.corp.network and it also fails. So I was wrong with my guess that the asterisk is missing. Thanks for pointing that out. So this is a bug in npm itself?
@StefanBauerTT I don't think that npm passes the proxy config to the git client. you could try to configure a no_proxy environment variable which should be used by git (i think also without *) So i think
<configuration>
<environmentVariables>
<no_proxy>.corp.network</no_proxy>
</environmentVariables>
</configuration>
should work.
I found the place where the proxy settings get passed from the frontend plugin to git via environment variables:
https://github.com/eirslett/frontend-maven-plugin/blob/b7b060fa13ca47e69172ee6d06194ffd41c35084/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NpmRunner.java#L54
Surprisingly though, the no_proxy environment variable is not set here, so right now I don't understand how adding git.corp.network to the <nonProxyHosts> of my maven settings.xml fixed the issue.
Ok, sorry for the confustion. Adding git.corp.network to the <nonProxyHosts> in the maven settings.xml acutally fixed nothing.
So the bottom line of this is that the frontend plugin sets the https_proxy but not the no_proxy environment variable. One could argue that this is inconsistent and can lead to confusing errors, just like the one I experienced.
I will leave it up to you if you consinder this a bug worth fixing or close this ticket with reference to @tkalmar 's workaround from https://github.com/eirslett/frontend-maven-plugin/issues/1172#issuecomment-2624910876 . Thank you for your time.