npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

Issue: Registry returns 500 'An error occurred' if Content-Length header is provided

What I Wanted to Do and What Happened

Our electron based application uses npm registry to query module updates which returns status code 500 with the text: ‘An error occurred’. This happens since end of May when npm migrated to new CDN.

It happens because module sets Content-Length: 0 header.

Reproduction Steps

Based on comment by @mrodem here:

$ npm install electron

$ cat > registry-test.js
const {app} = require('electron');
app.on('ready', () => {
    const {net} = require('electron');
    const request = net.request('');
    request.on('response', (response) => {
        console.log(`STATUS: ${response.statusCode}`);
        console.log(`HEADERS: ${JSON.stringify(response.headers)}`);
        response.on('data', (chunk) => {
            console.log(`BODY: ${chunk}`);
        response.on('end', () => {
            console.log('No more data in response.');

$ node_modules/.bin/electron registry-test.js

Platform Info

$ npm --versions
{ npm: '6.1.0',
  ares: '1.14.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.32.0',
  node: '10.7.0',
  openssl: '1.1.0h',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.22.0',
  v8: '',
  zlib: '1.2.11' }
$ node -p process.platform

This has been fixed (as of about 1 hour ago). GET and HEAD requests with a Content-Length: 0 will no longer produce 500s.

Great, it’s working, thank you!