Unhandled Runtime ErrorError: Cannot read properties of undefined (reading 'value')
Unanswered
Ghost ant posted this in #help-forum
Ghost antOP
I'm relatively new to Next.JS 13, doing a project in it following a course. But I ran into an error that I can't be able to fix. It shows the error from the title, the moment I import a <greeting/> component inside the home/page.tsx. The error comes from JWT.value, which basically means from my cookies. I can't narrow down the problem. It would mean a lot if someone could take a look! I've attached the files, from where the error is coming from.
If someone's interested in the full codebase repository: https://github.com/ZarifHosen/Project-Next.JS
If someone's interested in the full codebase repository: https://github.com/ZarifHosen/Project-Next.JS
5 Replies
@Ghost ant I'm relatively new to Next.JS 13, doing a project in it following a course. But I ran into an error that I can't be able to fix. It shows the error from the title, the moment I import a <greeting/> component inside the home/page.tsx. The error comes from JWT.value, which basically means from my cookies. I can't narrow down the problem. It would mean a lot if someone could take a look! I've attached the files, from where the error is coming from.
If someone's interested in the full codebase repository: https://github.com/ZarifHosen/Project-Next.JS
I can’t see the attached files due to me being on phone, but from the screenshot it looks like you don’t have the cookie so jwt is undefined so jwt.value throws that error
You need to check for that cookie’s existence first and handle the case where it doesn’t exist
And/or use jwt?.value with that question mark
Which essentially means jwt ? jwt.value : undefined
Ghost antOP
I tried to make it undefined using the question mark, but it still didn't work! @joulev