#ReferenceError: window is not defined

8 messages · Page 1 of 1 (latest)

bleak crater
#

the website is working properly but still why am i getting this error? Anyone please help 🙏

#

i just copied this in it

ashen jungle
#

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

bleak crater
ashen jungle
#

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

bleak crater
#

thanks bro 😍