【发布时间】:2020-06-07 21:33:57
【问题描述】:
是否可以在没有 esm 或 babel 的情况下使用 Jest 测试 ES6 模块?由于node v13原生支持es6 已经试过了:
//package.json
{
…
"type": "module"
…
}
//__tests__/a.js
import Foo from '../src/Foo.js';
$ npx jest
Jest encountered an unexpected token
…
Details:
/home/node/xxx/__tests__/a.js:1
import Foo from '../src/Foo.js';
^^^^^^
SyntaxError: Cannot use import statement outside a module
babel 加了转译器就可以了,但是 es6 模块也可以原生使用吗?
【问题讨论】:
-
Foo 是默认从 '../src/Foo.js' 导出的吗?
-
是的,就是这样。
-
根据issue#9430,(以及本期引用或提及的其他问题),似乎是babel或esm还是有必要的。
标签: node.js ecmascript-6 jestjs