NodeBas Mocha es6模块意外导出令牌而没有Babel

Car*_*rlo 5 javascript mocha.js node.js es6-modules

我正在尝试使用以下命令在ES6模块上对mocha进行一些单元测试:

node --experimental-modules .\node_modules\mocha\bin\mocha --reporter progress "client/assets/utils/url-utils.test.mjs"
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

(function (exports, require, module, __filename, __dirname) { export class URLUtils {
                                                              ^^^^^^
SyntaxError: Unexpected token export
Run Code Online (Sandbox Code Playgroud)

--experimental-modules参数不应该让我使用ES6模块吗?我宁愿避免为此使用Babel或其他编译器。

节点版本:11.7.0

摩卡版本:5.2.0

vin*_*yll 1

为了使用实验模块运行摩卡,您应该:

  1. 安装摩卡-erm:npm install mocha-esm --only-dev
  2. 运行你的测试npx mocha client/assets/utils/url-utils.test.mjs -r esm