Next.js Discord

Discord Forum

ReferenceError: document is not defined

Unanswered
Pharaoh Hound posted this in #help-forum
Open in Discord
Pharaoh HoundOP
Hello everyone,

I'm working on a Next.js application and have come across a persistent ReferenceError: document is not defined issue. Here's what's happening:



The error occurs when running my Next.js app, pointing to an issue with server-side code trying to access document, which should only be available on the client-side.
This error seems to come up when I'm trying to import and use Bootstrap in my application. Context:

The error persists despite the usual client-side checks and ensuring that Bootstrap is not being imported or used directly on the server side.
I've tried using useEffect and conditional typeof window !== 'undefined' checks to safeguard against SSR issues. Not using typescript

3 Replies