Esm: ESM+TS-Node+Mocha leads to Return statement outside of function body

Created on 28 Mar 2019  ·  1Comment  ·  Source: standard-things/esm

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.

bug needs tests

Most helpful comment

esm v3.2.21 is released :tada:

>All comments

esm v3.2.21 is released :tada:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MVSICA-FICTA picture MVSICA-FICTA  ·  3Comments

Mensu picture Mensu  ·  3Comments

OmgImAlexis picture OmgImAlexis  ·  3Comments

ericelliott picture ericelliott  ·  3Comments

bensampaio picture bensampaio  ·  3Comments