Windows is not Defined during prefetch
Unanswered
West African Lion posted this in #help-forum
West African LionOP
Hi, i am having problem with prefetch and prerendering.
In my code i have a simple layouts.tsx where i use router.prefetch("/private/settings) from next/navigation.
full log in file.
I rly could find an answer on this problem
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 Lion 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
Turkish Van
You are most likely trying to use
You might want to take a look here: https://www.youtube.com/watch?v=5QP0mvrJkiY&t=1673s
Also, even You are not trying to use it directly, but there might be a package that provides You with custom component that uses the
window
object without making sure that You are doing that on the client, and client only.You might want to take a look here: https://www.youtube.com/watch?v=5QP0mvrJkiY&t=1673s
Also, even You are not trying to use it directly, but there might be a package that provides You with custom component that uses the
window
object.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.