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

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

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 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