I am learning next.js and while working on a project I got this error.
I am using a module named Typed.js here It says Server Error ReferenceError: document is not defined
This error happened while generating the page. Any console logs will be displayed in the terminal window.
And tells that the problem is in this code.
When I comment out this code then website works fine and even if I remove the comment while the website is running then it works find. It only shows this when website is reloaded or refreshed completely.
//typing text animation script
var typed = new Typed(".typing", {
strings: ["Developer", "Designer"],
typeSpeed: 100,
backSpeed: 60,
loop: true
});
var typed = new Typed(".typing-2", {
strings: ["Game", "Graphic"],
typeSpeed: 100,
backSpeed: 60,
loop: true
});```
That happens because the script is called before the document or DOM content is loaded. I think you might want to check first if window is not undefined before initializing the Typed class, check below link for reference:
https://bobbyhadz.com/blog/javascript-referenceerror-document-is-not-defined