For Babel <6
The easiest way to solve this problem is:
npm install babel-preset-es2015 --save-dev
-
Add
.babelrc
to the root of the project with contents:{ "presets": [ "es2015" ] }
Ensure that you are running mocha with the “–compilers js:babel-core/register” parameter.
For Babel6/7+
npm install @babel/preset-env --save-dev
-
Add
.babelrc
to the root of the project with contents:{ "presets": [ "@babel/preset-env" ] }
Ensure that you are running mocha with the --compilers js:babel-register
(Babel 6) or --compilers js:@babel/register
(Babel 7) parameter
For mocha version 7 or later, use --require babel-register
or --require @babel/register
respectively.