Skip to content
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

Support require of ESM files #122

Closed
lieser opened this issue Jul 25, 2020 · 2 comments
Closed

Support require of ESM files #122

lieser opened this issue Jul 25, 2020 · 2 comments

Comments

@lieser
Copy link

lieser commented Jul 25, 2020

In my .mocharc.json I require an esm module. This is suported since Mocha 8.0.0 (mochajs/mocha#4304) and works fine if I run the tests from the command line.

With the adapter I however get the following error:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: <...>\dkim_verifier@pl\test\helpers\sinonRegisterNode.mjs.js
require() of ES modules is not supported.
require() of <...>\dkim_verifier@pl\test\helpers\sinonRegisterNode.mjs.js from c:\Users\<user>\.vscode\extensions\hbenl.vscode-mocha-test-adapter-2.7.0\out\worker\bundle.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename sinonRegisterNode.mjs.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from <...>\dkim_verifier@pl\package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1192:13)
    at Module.load (internal/modules/cjs/loader.js:1040:32)
    at Function.Module._load (internal/modules/cjs/loader.js:929:14)
    at Module.require (internal/modules/cjs/loader.js:1080:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at c:\Users\<user>\.vscode\extensions\hbenl.vscode-mocha-test-adapter-2.7.0\out\worker\bundle.js:5645:17
    at Generator.next (<anonymous>)
    at c:\Users\<user>\.vscode\extensions\hbenl.vscode-mocha-test-adapter-2.7.0\out\worker\bundle.js:88:71
    at new Promise (<anonymous>)
    at __awaiter (c:\Users\<user>\.vscode\extensions\hbenl.vscode-mocha-test-adapter-2.7.0\out\worker\bundle.js:84:12) {
  code: 'ERR_REQUIRE_ESM'
}

As far as I can tell from the Mocha Explorer Log, the new Mocha (8.0.1) locally installed is used:

[2020-07-25 17:17:20.958] [INFO] Worker: Using the mocha package at <...>\dkim_verifier@pl\node_modules\mocha
[2020-07-25 17:17:21.152] [INFO] Worker: Patching Mocha
@hbenl
Copy link
Owner

hbenl commented Jul 31, 2020

I have added support for this to version 2.7.1.
Please test and tell me if it works for you.

@lieser
Copy link
Author

lieser commented Aug 2, 2020

It works now, thanks for the fast fix

@lieser lieser closed this as completed Aug 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants