0

Im trying to get cookies on client side getCookie from cookies-next, and im facing issue that on initial render next.js is crashing with error Cannot read properties of undefined , but in console cookie has some value always.

When im trying to pass cookie from server using getServerSideProps, i get error from eslint Async arrow function 'getServerSideProps' has no 'await' expression. and when i remove async i get ts error getServerSideProps should return promise<...> etc

1 Answers1

0

I think this question is the same as yours: How to use cookie inside `getServerSideProps` method in Next.js?

ESLint is saying that you are unnecessarily marking getServerSideProps as async in a function that does not use await, however that syntax is required in Next.js so you can disable that rule.

Mart
  • 61
  • 5
  • when i remove `async` from `getServerSideProps` it shows `ts` error that `getServerSideProps should return Promise<....>` and etc – Олег Трухан Jul 07 '22 at 08:28
  • 1
    You're right, I think it might be a problem with ESLint. If you're using TS try adding the `GetServerSideProps` as seen [here](https://nextjs.org/docs/api-reference/data-fetching/get-server-side-props#getserversideprops-with-typescript), or just disable the ESLint rule entirely. Let me know what works and I will update my answer. – Mart Jul 07 '22 at 08:39
  • 1
    Probably easiest way will be just to disable ESlint rule – Олег Трухан Jul 07 '22 at 10:33