Closed martinslota closed 7 months ago
LGTM. I would test later with more cases
I tried adopting the fix released in version 1.9.1
but it seems that something else is now amiss:
$ npm test
> swc-node-register-mocha-bug@2.0.0 test
> node --import @swc-node/register/esm-register node_modules/mocha/bin/mocha test.spec.ts
file:///path/to/swc-node-register-mocha-bug/node_modules/mocha/bin/mocha.js:9
*/ const { loadOptions } = require('../lib/cli/options');
^
ReferenceError: require is not defined in ES module scope, you can use import instead
at file:///path/to/swc-node-register-mocha-bug/node_modules/mocha/bin/mocha.js:9:29
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
Node.js v20.11.0
@yeliex Could we maybe reopen this issue? Or is it better if I report a separate new one?
I opened a separate issue for the problem described above.
@martinslota see https://github.com/swc-project/swc-node/pull/781
When Mocha is used to run test files written in Typescript along with
--import=@swc-node/register/esm-register
, the following kind of error gets thrown:A specific reproduce along with a hacky fix can be found in this repository.
I'm not entirely sure what a proper fix would look like but I'd be happy to help with implementing it.