Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set headers after they are sent to the client #805

Open
chrisspen opened this issue Apr 8, 2022 · 2 comments
Open

Cannot set headers after they are sent to the client #805

chrisspen opened this issue Apr 8, 2022 · 2 comments
Labels

Comments

@chrisspen
Copy link

chrisspen commented Apr 8, 2022

Server is unable to send any requests.

Environment Versions

  1. OS Type = Ubuntu 20.04
  2. Node version: $ node --version = v10.24.1
  3. http-server version: $ http-server --version = 14.1.0

Steps to reproduce

#!/bin/bash
set -e
mkdir example
cd example
echo '{}' > package.json
npm install --save-dev webpack webpack-cli typescript ts-loader http-server
npx tsc --init

cat <<EOF > tsconfig.json
{
  "compilerOptions": {
    "target": "es2020",
    "module": "es2020",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}
EOF

cat <<EOF > webpack.config.js
module.exports = {
  entry: "./src/index.ts",
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: "ts-loader",
        exclude: /node_modules/,
      },
    ],
  },
  resolve: {
    extensions: [".tsx", ".ts", ".js"],
  },
  output: {
    filename: "bundle.js",
  },
  devServer: {
    publicPath: "/dist",
  },
};
EOF

cat <<EOF > index.html
<!DOCTYPE html>
<title>Demo</title>
<script src="./dist/bundle.js"></script>
<div>Hello World!</div>
EOF

mkdir src
cat <<EOF > src/index.ts

async function load() {
  document.body.textContent = JSON.stringify({123:'abc'});
}

load();
EOF

./node_modules/.bin/webpack --mode=development
./node_modules/.bin/http-server

Expected result

The file index.html is served.

Actual result

Upon making a request to http-server running at http://127.0.0.1:8080, it crashes with the error:

[Thu Apr 07 2022 22:45:19 GMT-0400 (Eastern Daylight Time)]  "GET /" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36"
_http_outgoing.js:470
    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:470:11)
    at module.exports.ResponseStream.(anonymous function) [as setHeader] (/project/sqljs/node_modules/union/lib/response-stream.js:100:34)
    at Object.exports.(anonymous function) (/project/sqljs/node_modules/http-server/lib/core/status-handlers.js:57:7)
    at Readable.stream.on (/project/sqljs/node_modules/http-server/lib/core/index.js:339:22)
    at Readable.emit (events.js:198:13)
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)
@zbynek
Copy link
Contributor

zbynek commented Apr 8, 2022

Duplicate of #756 -- Node 10 is not supported, please try Node 12.16 or later

@github-actions
Copy link

github-actions bot commented Oct 6, 2022

This issue has been inactive for 180 days

@github-actions github-actions bot added the stale label Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants