Server Error ReferenceError: window is not defined This error happened while generating the page. Any console logs will be displayed in the terminal window.
I am getting following exception in NextJS when I import one of my own component.
Server Error
ReferenceError: window is not defined
This error happened while generating the page. Any console logs will be displayed in the terminal window.
Module._compile
internal/modules/cjs/loader.js (688:30)
Object.Module._extensions..js
internal/modules/cjs/loader.js (699:10)
Module.load
internal/modules/cjs/loader.js (598:32)
tryModuleLoad
internal/modules/cjs/loader.js (537:12)
Function.Module._load
internal/modules/cjs/loader.js (529:3)
Module.require
internal/modules/cjs/loader.js (636:17)
require
internal/modules/cjs/helpers.js (20:18)
Module._compile
internal/modules/cjs/loader.js (688:30)
Object.Module._extensions..js
internal/modules/cjs/loader.js (699:10)
Module.load
internal/modules/cjs/loader.js (598:32)
tryModuleLoad
internal/modules/cjs/loader.js (537:12)
Function.Module._load
internal/modules/cjs/loader.js (529:3)
Module.require
internal/modules/cjs/loader.js (636:17)
require
internal/modules/cjs/helpers.js (20:18)
How can I sove this?
1 Answer
5 years ago by Karthik Divi
Looks like the library you are using is looking for window object.
So you need to stop rendering this at setver side.
You. can make the following change to your imports.
import dynamic from 'next/dynamic';
//import foo from '../foo.js';
const foo = dynamic(import('../foo.js'), { ssr: false });
5 years ago by Eleven