Next.js Discord

Discord Forum

Windows is not Defined during prefetch

Unanswered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
Hi, i am having problem with prefetch and prerendering.


Generating static pages (0/10)  [    ]ReferenceError: window is not defined
Error occurred prerendering page "/private/settings". Read more: https://nextjs.org/docs/messages/prerender-error


In my code i have a simple layouts.tsx where i use router.prefetch("/private/settings) from next/navigation.
/private
|-layouts.tsx
|-page.tsx
|-/settings
|--page.tsx

full log in file.
I rly could find an answer on this problem

6 Replies

Send the settings file
Spectacled bear
You want to check if windows exist first, make a check if
typeof window !== 'undefined'
and then use it
West African LionOP
Thx for all feedback , I fixed this by putting my router.prefetch inside a useEffect
@West African Lion Thx for all feedback , I fixed this by putting my router.prefetch inside a useEffect
Turkish Van
Make sure to mark it as answered, so thread gets closed.