Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

514
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!