Next.js Discord

Discord Forum

Deployment fails with `ReferenceError: localStorage is not defined`

Unanswered
Bonga shad posted this in #help-forum
Open in Discord
Bonga shadOP
Maybe a bug but I'm not sure!

next dev works correctly but next build fails and thus the deployment.

I'm using the local storage in a hook defined in a "use client" module. And the only component that consumes it, it's also a client component.

I tried to add guards like
typeof window !== 'undefined' ? localStorage?.getItem('someKey') : null to no avail

0 Replies