WebStorm's Mocha test runner breaks with Mocha 12 (ERR_REQUIRE_ESM) - mocha's own package converted to ESM
Mocha 12 (stable, released early September 2026) converted mocha's own
internals to ESM: its root package.json now has "type": "module", and
the CLI entrypoint / worker pool modules were rewritten as ESM
(mochajs/mocha#6014, mochajs/mocha#6015).
WebStorm's built-in Mocha test runner integration launches tests via
node_modules/mocha/bin/_mocha (needed so the debugger/test-tree
integration works), rather than the regular node_modules/.bin/mocha CLI
wrapper. Unlike the CLI wrapper, _mocha runs lib/cli/cli.js directly and
does not have the same ESM-bootstrapping logic - so with mocha 12 it now
fails (ERR_REQUIRE_ESM or similar), even though `npm test` / running
`mocha` from a terminal works fine.
This is the same underlying class of issue previously reported for
projects with their own "type": "module" package.json (see
https://intellij-support.jetbrains.com/hc/en-us/community/posts/360007103439-Mocha-doesn-t-take-in-account-esm-package),
but now triggers for ANY project using mocha 12, regardless of the
project's own module type, since mocha itself is ESM now.
Steps to reproduce:
1. In a Node/TypeScript project, install mocha@12.x as a dev dependency.
2. Create a WebStorm "Mocha" run configuration (or use the gutter icon)
pointing at a test file.
3. Run it.
Expected: tests run normally, same as `npm test` / `npx mocha` in a
terminal.
Actual: the run fails with an ESM-related error (ERR_REQUIRE_ESM or
equivalent), because WebStorm invokes node_modules/mocha/bin/_mocha
directly instead of the ESM-aware node_modules/.bin/mocha wrapper.
Environment: WebStorm <your version>, Node <your version>, mocha 12.0.1.
Related mocha PRs (root cause):
- https://github.com/mochajs/mocha/pull/6014
- https://github.com/mochajs/mocha/pull/6015
请先登录再写评论。
Unfortunately I failed to reproduce the issue. The only problem I've faced when running Mocha 12.x is the “cannot load base reporter” warning (WEB-79510, fixed in 2026.3 EAP).
Can you please share a bit more context around the problem? Which version of the IDE are you using? It would help a lot if you could share a file or a small project that we could use to reproduce the problem.