-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameter --require
cannot load an ES module.
#4281
Comments
This is known, and is a "missing feature" |
Ran into this issue as well. In a quick dive through the code, this seems like a feasible and quick tweak to support. I am happy to take a swing at a PR, but I wanted to discuss possible reasons not to support this, or alternative solutions. The error spawns here: https://github.com/mochajs/mocha/blob/master/lib/cli/run-helpers.js#L92 See how the require method is being used directly. If we swapped that require with the existing requireOrImport it should auto-magically support ESM. Of course that makes the "require" async, but considering the handleRequires already has an async signature, there would not need to be any change to that methods usage. Would just need to convert that .reduce() into something async friendly (for ... of?). |
Allow files/modules specified in `--require` to be ESM. CommonJS loading is still supported and the default.
* Support --require of ESM; closes #4281 Allow files/modules specified in `--require` to be ESM. CommonJS loading is still supported and the default. * Conditionally generate url for import Windows compatible * Add tests for --require ESM As both .mjs and type=module (combined with cjs for good measure). Updated linter to allow tests to use spread operator (ecmaVersion 2018) Allow --require'd module to be an object, or "module" * Revert change to eslintrc, use mocha to pass experimental flag * Replace type() -> typeof Add truthy check to handle null edge case type(ES Module) => "module", but we treat it the same as an object * Remove doc limitation for --require ESM * Add note to --require docs about ESM support
Prerequisites
faq
labelnode node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.Description
Parameter
--require
cannot load an ES module.Steps to Reproduce
// An ES module because { "type": "module" } in package.json.
npm install
npm test
Expected behavior: [What you expect to happen]
Actual behavior: [What actually happens]
Reproduces how often: [What percentage of the time does it reproduce?] 100%
Versions
mocha --version
: zsh: command not found: mochanode node_modules/.bin/mocha --version
: 7.1.2node --version
: v13.14.0Additional Information
Fix proposal: replace
require
byimport
. But dynamic import has been added to Node 13.2.0.The text was updated successfully, but these errors were encountered: