Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
Next js throws unexpected document not defined error

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.

Image of the error

Link to the index.js file

//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
 });```


about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!