Skip to content

Error: Cannot set headers after they are sent to client, occurs when trying to serve index.html, only occurs in v14.0.0 #756

@abhimonk

Description

@abhimonk

Getting the following error when trying to go to the webpage returned by "npx http-server" serving my index.html:

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

The issue does not occur if I use version 13.0.0

(See below for full stack trace)

If I repeat the reproduction steps with version 13.0.0, it works as expected.

Environment Versions

  1. OS Type: Windows
  2. Node version: 6.13.4
  3. http-server version: 14.0.0

Steps to reproduce

  1. Have just any index.html in your current folder
  2. Run "npx http-server" from the current folder
  3. Navigate to the URL returned (which should trigger serving your index.html)

Expected result

My index.html should be served and the contents of it should be displayed. This works fine in version 13.0.0.

Actual result

The server crashes with the following error:

[2021-10-23T17:10:29.869Z] "GET /" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36"
(node:3956) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
_http_outgoing.js:485
throw new ERR_HTTP_HEADERS_SENT('set');

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:485:11)
at module.exports.ResponseStream. [as setHeader] (C:\Users\abhim\Documents\GameDev\JSDev\AttackAnimationGenerator\node_modules\union\lib\response-stream.js:100:34)
at Object.exports. (C:\Users\abhim\Documents\GameDev\JSDev\AttackAnimationGenerator\node_modules\http-server\lib\core\status-handlers.js:57:7)
at Readable. (C:\Users\abhim\Documents\GameDev\JSDev\AttackAnimationGenerator\node_modules\http-server\lib\core\index.js:339:22)
at Readable.emit (events.js:210:5)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
code: 'ERR_HTTP_HEADERS_SENT'
}

Other information

I have seen the github issue #634, but it looks like their server is undergoing external traffic. I am just using my server for local testing with a simple index.html. This workflow worked fine in version 13.0.0, but when I switched to version 14.0.0 I get the above error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions