#ReferenceError: window is not defined
8 messages · Page 1 of 1 (latest)
i think you are trying to access the window object in the server side that's why it's giving you the reference error for window object as the object is only declared at the browser(client-side) not at the server-side
can you provide me a fix pls
ya sure
make a new component to stop server-side rendering "// Import dynamic from next/dynamic
import dynamic from 'next/dynamic';
// Dynamically import the Globe component with SSR disabled
const GlobeWithNoSSR = dynamic(() => import('./Globe'), { ssr: false });
// Use the dynamically imported component in your component or page
function MyPage() {
return (
<div>
<GlobeWithNoSSR />
</div>
);
}
export default MyPage;" and use this in the globe (add this <GlobeWithNoSSR />) and then modify WebGLRendererConfig func. as : export function WebGLRendererConfig() {
const { gl, size } = useThree();
useEffect(() => {
// Ensure window is defined before using it
if (typeof window !== 'undefined') {
gl.setPixelRatio(window.devicePixelRatio);
gl.setSize(size.width, size.height);
gl.setClearColor(0xffaaff, 0);
}
}, []);
return null;
}
i think that should do it
thanks bro 😍