I am trying to start Mocha using ESM and TS-Node. Everytime I do so with a .ts file as target, the following error occurs:
error TS1108: A 'return' statement can only be used within a function body.
The output code in the error message indeed shows a return statement not wrapped inside a function:
const _1f5=exports;return _1f5.r((function *(exports,require){"use strict";let something;_1f5.w("./export",[["something",["something"],function(v){something=v}]]);yield;_1f5.s();
The NPM script is: mocha -r esm -r ts-node/register *.ts
Using .js files as target does not cause this error.
My assumption is that ESM may convert the import code erroneous in this case.
For easier reproduction of the error, here is the minimal example to check out and test: https://github.com/MetalSkotty/esm_ts-node_mocha_bug
Usage: npm run test:ts uses the .ts files. npm run test:js uses the .js files.
esm v3.2.21 is released :tada:
Most helpful comment
esmv3.2.21 is released :tada: