react-redux-universal-hot-example: TypeError: res.writeHead is not a function

Hi, I’ve done this with your latest code:

npm run build npm run start

Right after the Open http://localhost:8080 in a browser to view the app. message, I get an exception:

[0] /Users/me/projects/react-redux-universal-hot-example/src/server.js:105
[0]     res.writeHead(500, { 'content-type': 'application/json' });
[0]         ^
[0] 
[0] TypeError: res.writeHead is not a function
[0]     at ProxyServer.<anonymous> (/Users/me/projects/react-redux-universal-hot-example/src/server.js:55:9)

This is the code that fails:

// added the error handling to avoid https://github.com/nodejitsu/node-http-proxy/issues/527
proxy.on('error', (error, req, res) => {
  let json;
  if (error.code !== 'ECONNRESET') {
    console.error('proxy error', error);
  }
  if (!res.headersSent) {
    res.writeHead(500, {'content-type': 'application/json'});   // <- EXCEPTION
  }

I installed the latest http-proxy package but nothing changed.

Thanks, Alvaro

About this issue

Commits related to this issue

Most upvoted comments

@stalkingbutler I also run into this problem whenever I change the server side code. Instead of removing the line all together, I added a check to see if res.writeHead is a function. So far so good.

if (!res.headersSent) {
  if (typeof res.writeHead === 'function') res.writeHead(500, {'content-type': 'application/json'});
}

I know WHY!!! You must have run some other NodeJS App which use app cache on port 3000, and your browser must be Chrome! It’s ok when use Safari!!! @alvaro1728