I'm trying to run a Mocha test with some ES6 style imports in the file but I keep getting the error:
import assert from 'assert';
^^^^^^
SyntaxError: Unexpected identifier
I tried to invoke mocha with both
mocha --require @babel/register --recursive
and
mocha --require babel-register --recursive
but the error would not go away.
What is the correct way to run ES6 style Mocha tests?
For anyone coming from Google:
You can also install esm: npm i esm --save-dev
or use your preferred package manager.
Then pass it as an argument to mocha: mocha 'index.test.js' --require esm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With