Cannot read properties of null reading useContext
Unanswered
Cape lion posted this in #help-forum
Cape lionOP
I keep getting this error randomly in my project. I am using NextJS 14.2.16, App router, shadcn/ui, react-hook-form, turbopack. I encountered this error in other versions of NextJS. I really don't understand where is this coming from. I understand that it must be context specific but all of my client components are marked with use client directive, I don't use context except for sonner package from shadcn/ui and a theme provider from shadcn/ui. I have spent too many hours trying to debug this.
7 Replies
Golden northern bumble bee
Also running into this on nextjs 15 recently during the build. Are you using bun workspaces by any chance?
I’ve seen multiple threads open in the discord and GitHub. No solutions worked for me except for adding react and react-DOM as peer dependencies in all my packages that lived in my bun workspaces monorepo, no clue why
Cape lionOP
No workspaces. I have this error for 3 months. I really don’t get it.
In dev mode I sometimes work for hours whithout seeing it and then at some point it starts. When I make any modifications to my code it goes away, but it is very frustrating.
Golden northern bumble bee
That’s odd for sure, have you updated any packages lately?
Cape lionOP
Not a single one. I use this stack in all of my recent projects. NextJS, shadcn, tailwind. As I said the only components that are using useContext are orobably shadcn components, sonner toast library. I have a file marked with use client where is the orovoder for sonner and Next themes. I have seen the github discussions but doesn’tseem to lead anywhere. I amalso using —turbo in my dev environment. I tried whothout it and the error keeps on showing randomly.
Golden northern bumble bee
Yeah it’s super weird. I am not sure.