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

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 join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants