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

DeprecationWarning: OutgoingMessage.flush is deprecated. #28

Open
digi-chris opened this issue Apr 28, 2020 · 8 comments
Open

DeprecationWarning: OutgoingMessage.flush is deprecated. #28

digi-chris opened this issue Apr 28, 2020 · 8 comments

Comments

@digi-chris
Copy link

Using the latest version of Node, I'm getting the following warning when a client is connected to the SSE endpoint and a server event is sent:

(node:16688) [DEP0001] DeprecationWarning: OutgoingMessage.flush is deprecated. Use flushHeaders instead.

I think this is likely related to commit 96723a0, which added res.flush() after the message is sent.

@cooper667
Copy link

I've removed the res.flush() when I'm using it, and have instead set the compression module to ignore SSE. Not sure if it's worth removing it here and documenting that instead?

  app.use(
    compression({
      filter: (req, res) =>
        !res.getHeaders()["content-type"].includes("text/event-stream"),
    })
  );

@apparebit
Copy link

@cooper667, the more general solution would be to include no-transform in the Cache-Control header. Not only does compression respect that directive but any proxy between client and server, too. Unfortunately, this package hardcodes the header value to no-cache.

@kirushyk
Copy link

kirushyk commented Sep 5, 2020

In recent node, express-sse doesn't work at all for this reason.

@damnms
Copy link

damnms commented Oct 20, 2020

same problem here. seems incompatible. node just crashes

@bradisbell
Copy link

Looks like there is already a pull request out there to handle no-transform. #31 Now, we just need to fix the flush().

@wiegvlieg
Copy link

wiegvlieg commented Feb 4, 2021

It seems that there is not so much activity here right now. For people that are still looking for a solution for the res.flush() problem (TypeError: res.flush is not a function) and are not using the compression middleware for express.js. You can create a simple middleware function for express that adds the function.

The following piece of code could maybe help some people:

app.use(function (req, res, next) {
  res.flush = function () { /* Do nothing */ }
  next();
})

This adds the empty function to res object and express-sse will not crash anymore. You can also just downgrade your express-sse package in package.json and set it fixed to 0.5.1 for now. The other solution is to start using another package. But mostly this requires modifying existing code.

This pull request would solve the problem i think.
2f8f08d

I hope this helps some people.

@aguegu
Copy link

aguegu commented Apr 3, 2021

@wiegvlieg , to reduce the workaround affect area, we can do it like this:

app.get('/sse', (req, res, next) => {
  res.flush = () => {}; 
  next();
}, sse.init);

@Samueloyeks
Copy link

It seems that there is not so much activity here right now. For people that are still looking for a solution for the res.flush() problem (TypeError: res.flush is not a function) and are not using the compression middleware for express.js. You can create a simple middleware function for express that adds the function.

The following piece of code could maybe help some people:

app.use(function (req, res, next) {
  res.flush = function () { /* Do nothing */ }
  next();
})

This adds the empty function to res object and express-sse will not crash anymore. You can also just downgrade your express-sse package in package.json and set it fixed to 0.5.1 for now. The other solution is to start using another package. But mostly this requires modifying existing code.

This pull request would solve the problem i think. 2f8f08d

I hope this helps some people.

this helped me thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants