You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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) and mocha --version(Global). We recommend that you not install Mocha globally.
Description
Assume a test file with a broken import statement, e.g. due to the requested package not being installed.
The containing package is ESM, so package.json: "type": "module"
this results in very confusing errors: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: myTestFile.spec.js
Steps to Reproduce
Assume a test file with a broken import statement, e.g. due to the requested package not being installed.
The containing package is ESM, so package.json: "type": "module"
Mocha tries to import the file via import, due to mocha/lib/esm-utils.js:42
If the loaded file has a problem in its imports, the catch statement catches the error and tries to load the file as a commonjs module.
this results in very confusing errors: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: myTestFile.spec.js
Expected behavior: The import error from the test file is displayed so I can diagnose it (especially important for CI where I can't easily reproduce the error locally)
Actual behavior: The import error from the test file is hidden, instead the test file gets imported with require() resulting in another error message that has nothing to do with the actual problem
Reproduces how often: 100%
Versions
The output of mocha --version: command not found
The output of node node_modules/.bin/mocha --version: 9.0.2
The output of node --version: 16.5.0
Your operating system
name and version: OSX 10.15.7 & ubuntu20.04
architecture (32 or 64-bit): 64bit
Your shell (e.g., bash, zsh, PowerShell, cmd): zsh
Any third-party Mocha-related modules (and their versions): none
Any code transpiler (e.g., TypeScript, CoffeeScript, Babel) being used (and its version): typescript, but replicates with *.js files as well
The text was updated successfully, but these errors were encountered:
Prerequisites
faq
labelnode node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.Description
"type": "module"
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: myTestFile.spec.js
Steps to Reproduce
"type": "module"
import
, due tomocha/lib/esm-utils.js:42
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: myTestFile.spec.js
Expected behavior: The import error from the test file is displayed so I can diagnose it (especially important for CI where I can't easily reproduce the error locally)
Actual behavior: The import error from the test file is hidden, instead the test file gets imported with require() resulting in another error message that has nothing to do with the actual problem
Reproduces how often: 100%
Versions
mocha --version
: command not foundnode node_modules/.bin/mocha --version
: 9.0.2node --version
: 16.5.0The text was updated successfully, but these errors were encountered: