mocha -r esm: ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING
See original GitHub issuePrerequisites
- Checked that your issue hasn’t already been filed by cross-referencing issues with the
faq
label - Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn’t just a feature that actually isn’t supported in the environment in question or a bug in your code.
- ‘Smoke tested’ the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
- Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with:
node node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.
Description
Since version v9.0.0 mocha crashes when I try to use it with ESM.
Steps to Reproduce
Expected behavior: [What you expect to happen] Mocha should run successfully.
Actual behavior: [What actually happens]
Mocha crashes.
Stack trace:
TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.
at new NodeError (node:internal/errors:363:5)
at exports.importModuleDynamicallyCallback (node:internal/process/esm_loader:34:9)
at formattedImport (/Users/yonom/GitHub/test/mocha-bug-report/node_modules/mocha/lib/esm-utils.js:7:31)
at Object.exports.requireOrImport (/Users/yonom/GitHub/test/mocha-bug-report/node_modules/mocha/lib/esm-utils.js:48:38)
at Object.exports.loadFilesAsync (/Users/yonom/GitHub/test/mocha-bug-report/node_modules/mocha/lib/esm-utils.js:73:34)
at Mocha.loadFilesAsync (/Users/yonom/GitHub/test/mocha-bug-report/node_modules/mocha/lib/mocha.js:467:19)
at singleRun (/Users/yonom/GitHub/test/mocha-bug-report/node_modules/mocha/lib/cli/run-helpers.js:125:15)
at exports.runMocha (/Users/yonom/GitHub/test/mocha-bug-report/node_modules/mocha/lib/cli/run-helpers.js:190:10)
at Object.exports.handler (/Users/yonom/GitHub/test/mocha-bug-report/node_modules/mocha/lib/cli/run.js:366:11)
at /Users/yonom/GitHub/test/mocha-bug-report/node_modules/yargs/build/index.cjs:443:71
at process.runNextTicks [as _tickCallback] (node:internal/process/task_queues:61:5)
at /Users/yonom/GitHub/test/mocha-bug-report/node_modules/esm/esm.js:1:34535
at /Users/yonom/GitHub/test/mocha-bug-report/node_modules/esm/esm.js:1:34176
at process.<anonymous> (/Users/yonom/GitHub/test/mocha-bug-report/node_modules/esm/esm.js:1:34506)
at Function.<anonymous> (/Users/yonom/GitHub/test/mocha-bug-report/node_modules/esm/esm.js:1:296856)
at Function.<anonymous> (/Users/yonom/GitHub/test/mocha-bug-report/node_modules/esm/esm.js:1:296555)
at Function.<anonymous> (/Users/yonom/GitHub/test/mocha-bug-report/node_modules/esm/esm.js:1:284879)
at Object.apply (/Users/yonom/GitHub/test/mocha-bug-report/node_modules/esm/esm.js:1:199341)
at node:internal/main/run_main_module:17:47
Reproduces how often: [What percentage of the time does it reproduce?]
100% (always)
Versions
- The output of
mocha --version
andnode node_modules/.bin/mocha --version
: 9.0.1 - The output of
node --version
: v16.4.0 (also tested on v14.17.1) - Your operating system
- name and version: macOS 11.4 (also tested on GitHub Actions Ubuntu 20.04)
- architecture (32 or 64-bit): 64-bit
- Your shell (e.g., bash, zsh, PowerShell, cmd): zsh (also tested on bash)
- Your browser and version (if running browser tests): N/A
- Any third-party Mocha-related modules (and their versions): N/A
- Any code transpiler (e.g., TypeScript, CoffeeScript, Babel) being used (and its version): ESM v3.2.25
Additional Information
Repository for reproduction: https://github.com/Yonom/mocha-bug-report
You can run yarn test
in the (mostly empty) repo abobe to see the error occur. No actual tests are needed, an empty test file suffices to trigger the issue (but the error still happens even with real tests existing of course).
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (8 by maintainers)
Top Results From Across the Web
Mocha tests with 'esm' support for native ES6 modules
I've tried to use mocha with native ES modules support in my project and I had 2 different errors: $ ./node_modules/mocha/bin/mocha --require ...
Read more >Testing ESM with Mocha and testdouble.js - Test Double | Blog
Mocha unit tests and mocking with native ESM, and the journey it took to get there.
Read more >Mocha - the fun, simple, flexible JavaScript test framework
simple, flexible, fun. Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun....
Read more >Mocha doesn't take in account esm package
Hello, since today I was using run configuration of npm script which was doing this: "test": "mocha -r...
Read more >mochajs/mocha - Gitter
I'm getting Error [ERR_REQUIRE_ESM]: Must use import to load ES Module . The Internet tells me using -r esm should solve this, but...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
OK, I tried. I added the code above, but while trying to write a test that used the
esm
package, I got all sorts of weird unexplainable behaviors. I could spend a few days figuring things out and maybe getting it to work, but as @juergba said, it’s not worth it for a package that hasn’t been maintained for 2 years.So, sorry @Yonom, but it seems you’ll have to stick to Mocha v8 till you ugprade to native Node.js ESM, or submit a PR (with a test) yourself.
ok, thank you @giltayar @Yonom can I close?