cookies: Missing the cookie header or object

I am using universal-cookie and am experiencing this problem when instantiating it. I’m doing the same thing as the example:

import Cookies from 'universal-cookie';
const cookies = new Cookies();

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 11
  • Comments: 26

Most upvoted comments

Just to loop back, our solution was to just stub this object.

@eXon I am doing server side rendering and I would like to know if it’s possible to get instance of the cookie object outside a component. I am getting the same errors as @andrefox333.

I have a single util function and I want to know if I need to give the cookie from the component as a new argument at every call or I might be able to access it as a “global”.

@Brantron can you provide a code example of what you described above?

@mmoustai You must pass the Cookies object as an argument. You cannot use a global variable otherwise you risk hijacking the cookies from another user.

I came across this issue when using Next.js for server side rendering.

My solution was: Instead of initializing object from class in global scope, I moved it to componentDidMount and this error was gone, hope it helps!

  componentDidMount(){
    const cookies = new Cookies()
    ...
  }

Using 2.0.8 and getting error: Error: Missing the cookie header or object.

Using universal-cookie with server side rendering and hot reload. I would comment out the code, refresh the page and it loads the page. I’ll then uncomment the new Cookie() code and reload the page and it fully works after that…