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

543
Visualizações
ReferenceError: document is not defined in Visual Studio Code

Why wouldn't node.js recognize my index.html reference in the script.js file?

Pardon me for the dumb question but I couldn't find any fix and I've done copied perfectly a script from a YouTube tutorial and they seem to have no problem (neither do others, same method) but when I get to run node script.js in the terminal (or refreshing the html page in browser) nothing seems to work as it should and the html page remains static. I tried browsify and jsdom and what other suggested before in here but I wasted the same time with those too.

So here it is, even put it twice, once above </body> and once above </head>:

<script scr="script.js"defer></script>
...
    <div class="countdown-days-c">
        <p class="big-text"id="days">0</p>
        <span>days</span>
    </div>

And in the JS file like:

const daysElement = document.getElementById("days");

followed by this error

ReferenceError: document is not defined
    at Object.<anonymous> (C:\Users\......\script.js:6:16)
    at Module._compile...

and so on. Maybe I just missed something but I did exactly as shown and I've been struggling with this for some time now. I don't have any problem with the CSS file and the JS file can run perfectly standalone, but can't seem to work with the HTML.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can't run the app in node because the global objects are different. What you should do is open the HTML file in the browser instead. That should solve all your problems.

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