npm publish doesn't respect noproxy configuration

cli
priority:low
triaged

(Chris Wainwright) #1

What I Wanted to Do

I am trying to run npm publish to publish a package to an internal registry whilst still retaining proxy configuration for access to the public npmjs registry from behind a corporate proxy.

The internal registry is not behind the proxy.

I am trying to do this with the noproxy config setting in my npmrc file.

What Happened Instead

publish fails with the following error

npm ERR! publish Failed PUT 502
npm ERR! Unexpected token < in JSON at position 0
npm ERR! <html><head><title>502 Bad Gateway</title></head>
npm ERR! <body><h1>DNS error</h1>
npm ERR! <p>DNS error (the host name of the page you are looking for does not exist)<br><br>Please check that the host name has been spelled correctly.<br></p>
npm ERR! <!--Zscaler/5.6--></body></html>

Reproduction Steps

The following is done behind a corporate proxy.

Setup proxy configuration options in your global config npmrc file, e.g.

proxy=http://proxy.example.com:80/
https-proxy=http://proxy.example.com:443/
noproxy=my-company-registry
strict-ssl=false

here my-company-registry is the domain for the internal registry to which I want to publish a package.

Create a package (npm init) on your local machine, with the following .npmrc file in the root of the package to point it to the internal registry

registry=http://my-company-registry/path/to/registry
always-auth=true

Open a command prompt inside this package and try running npm publish. This results in the above mentioned error.

Details

Note that npm install works with this configuration for installing from both the public and internal registries, which suggests the configuration is correct.

npm publish works to the internal registry if I remove all proxy configuration settings, so it is not a problem with the internal registry.

npm publish works to the internal registry and npm install from internal and public if I remove all proxy settings from the configuration file and instead set HTTPS_PROXY and NO_PROXY environment variables. So it seems to be a problem with the way the noproxy setting is being passed from config to publish.

Platform Info

$ npm --versions
{ npm: '6.4.1',
  ares: '1.14.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.33.0',
  node: '10.11.0',
  openssl: '1.1.0i',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.0',
  v8: '6.8.275.32-node.28',
  zlib: '1.2.11' }

$ node -p process.platform
win32

(Chris Wainwright) #2

Has no-one else experienced this issue?


(mcenkar) #3

I can confirm on:

+ npm --versions
{ npm: '6.4.1',
  ares: '1.14.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.33.0',
  node: '10.11.0',
  openssl: '1.1.0i',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.0',
  v8: '6.8.275.32-node.28',
  zlib: '1.2.11' }

(Elouan Keryell-Even) #4

Witnessing the same behavior, with npm 5.6.0.

As a workaround, I get rid of all my proxy configuration before performing npm publish:

npm c delete proxy
npm c delete https-proxy
unset http_proxy https_proxy
sed -i '/proxy/d' /usr/local/etc/npmrc
sed -i '/https-proxy/d' /usr/local/etc/npmrc
npm publish

(Kat Marchán) #5

This will be fixed as soon as https://github.com/npm/cli/pull/2 lands.