Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

ESM+TS-Node+Mocha leads to Return statement outside of function body #769

Closed
erikroe opened this issue Mar 28, 2019 · 1 comment
Closed

Comments

@erikroe
Copy link

erikroe commented Mar 28, 2019

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.

@jdalton
Copy link
Member

jdalton commented Mar 29, 2019

esm v3.2.21 is released 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants