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

515
Vistas
Mocha with --watch flag set throws an error when using ES6 modules

I've been trying to set up Mocha to automatically watch for changes in my files by using the --watch flag. I've set up two scripts in package.json like so:

  "test": "mocha",
  "test:watch": "mocha --watch ./test ./game_logic" 

When invoking the first script with npm test the tests are performed without an error, however when I invoke the second script with npm run test:watch, the following error is thrown:

 (node:149779) UnhandledPromiseRejectionWarning: Error [ERR_REQUIRE_ESM]: Must use import to load 
 ES Module: <path to test file contained in /test>

I don't quite understand the error message because I'm already using import whenever I'm importing whole files or separate functionalities from one file into another.

The documentation from Mocha states that writing test as ES modules is supported so I really don't have a clue why the described error occurs.

https://mochajs.org/#nodejs-native-esm-support

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

As per this issue, a workaround is to add the --parallel flag, like so:

mocha --watch --parallel --recursive test
over 4 years ago · Santiago Trujillo 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