Next.js Discord

Discord Forum

Error occurred prerendering page "/details"

Unanswered
Spectacled bear posted this in #help-forum
Open in Discord
Spectacled bearOP
Error occurred prerendering page "/details". Read more: https://nextjs.org/docs/messages/prerender-error
ReferenceError: window is not defined

Export encountered errors on following paths:
/(loggedIn)/details/page: /details

Code inside Details/page.tsx

"use client";

import DetailSlider from "./details-components/DetailSlider";

const Details = () => {
return (
#Unknown Channel
<div>
<h1 className="text-xl md:text-3xl">Create your own Portfolio</h1>
<p className="text-md mt-3 text-gray-700">
The experience you have with us can be updated at any time whenever
you wish
</p>
</div>
<DetailSlider />
</>
);
};

export default Details;

10 Replies

Spectacled bearOP
Im not using window anywhere in code
Spectacled bearOP
Anyone?
Spectacled bearOP
"use client";

import dynamic from "next/dynamic";

const DynamicDetailSlider = dynamic(
() => import("./details-components/DetailSlider"),
{
ssr: false,
}
);
const Details = () => {
return (
#Unknown Channel
<div>
<h1 className="text-xl md:text-3xl">Create your own Portfolio</h1>
<p className="text-md mt-3 text-gray-700">
The experience you have with us can be updated at any time whenever
you wish
</p>
</div>
<DynamicDetailSlider />
</>
);
};

export default Details;

this fixed the issue but could anyone explain why?
I've use client on top of Details page and DetailSlider is a child component of Detail page so automatically it should become Client side component
@Anay-208 and `dynamic` makes it completely render in client with disabled ssr, hence fixing the error. Its better to use dynamic in the client component, in the module which is causing the error
Spectacled bearOP
ok but why use client wasnt enough for component to render on client side? I've many components which requires client side functionality and they are working just fine with use client
@Spectacled bear ok but why use client wasnt enough for component to render on client side? I've many components which requires client side functionality and they are working just fine with use client
American Crow
Despite the name "use client" components get rendered on the client and the server. Some of your client components work because they use the browser-only apis correctly. For example using windowwithin a useEffectthat would signal the server not to run what's inside of it.
Your DetailSlider makes problem because it (or one of its imports) use window, but not safely ( no useEffect, no checking if code is run on server ). Hence the server tries to run the window. functionality and the error is thrown