Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

266
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda