i18next / i18next-express-middleware

[deprecated] can be replaced with i18next-http-middleware
https://github.com/i18next/i18next-http-middleware
MIT License
206 stars 52 forks source link

ERR_HTTP_HEADERS_SENT Cannot set headers after they are sent to the client #143

Closed felquis closed 6 years ago

felquis commented 6 years ago

I'm getting this error, I think it is related to this module, I used the example from react-i18next, with nextjs.

I'm using this detection config:

    detection: {
      order: ['querystring', 'cookie', 'header'],
      lookupQuerystring: 'lng',
      lookupCookie: 'lng',
      lookupSession: 'lng',
      caches: ['cookie'],
    }

My browser is in pt-BR, and I request the page with ?lng=en, I think it sets up the pt-BR language, then it tries to set to en and the server crashes with this error.

I can post the entire server.js if it would help.

jamuhl commented 6 years ago

did you use the https://github.com/i18next/i18next-express-middleware#language-detection !?!

full server.js might help...

yasincanakmehmet commented 6 years ago

I did a quickfix by checking if the headers are set before setting the cookies. I thought it was fixed with 1.0.10 but I realized I had the cache set to false :) I will create a PR for the fix as soon as I can.