Reputation: 401
I am trying to run with some unit test with mocha on ES6 modules with the following command:
node --experimental-modules .\node_modules\mocha\bin\mocha --reporter progress "client/assets/utils/url-utils.test.mjs"
But I get the following error:
(function (exports, require, module, __filename, __dirname) { export class URLUtils {
^^^^^^
SyntaxError: Unexpected token export
Isn't the --experimental-modules
param supposed to let me use ES6 modules? I would prefer to avoid using Babel or other transpilers for this.
Node version: 11.7.0
Mocha version: 5.2.0
Upvotes: 5
Views: 687
Reputation: 11409
In order to run mocha with experimental modules, you should:
npm install mocha-esm --only-dev
npx mocha client/assets/utils/url-utils.test.mjs -r esm
Upvotes: 1