Next.js Discord

Discord Forum

NextJS: 500 (Internal Server Error) when trying to get windows pathname on client side rendering

Unanswered
Indian oil sardine posted this in #help-forum
Open in Discord
Indian oil sardineOP
I'm using 14.1.0 version of NextJS and whenever I try to get information from window, for example window.location.hostname or widow.innerHeight or even screen.width, I get this error on console " http://localhost:3000/page1 500 (Internal Server Error)"

Even console gives me an error, despite I have "use client" at the top of the page

The interesting part is that when I set timeout for 1 millisecond and then run the code, it doesn't show any error

This is the code of my page, it's not importing any other components, dependencies or something like that

"use client";
const Page = () => {
const screen = screen.width;

return (
#Unknown Channel
<div className="page">page1</div>
<div className="page">{screen}</div>
</>
);
};

export default Page;

Pls let me know, what is the problem and should I be worried about it

Thanks

0 Replies