Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

539
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda