[英]Cannot use import statement outside a module node.js using jest
I have this in index.js function sum(a, b) => a + b exports = { sum }
and in index.spec.js I do我在 index.js function sum(a, b) => a + b exports = { sum }
和 index.spec.js 中有这个
import { sum } from './index.js'
then I got error of SyntaxError: Cannot use import statement outside a module
然后我得到了SyntaxError: Cannot use import statement outside a module
错误SyntaxError: Cannot use import statement outside a module
I'm using node v12, what's the problem here?我正在使用 node v12,这里有什么问题? I don't want to use export defaults
because I have more than 1 function inside index.js我不想使用export defaults
因为我在 index.js 中有超过 1 个函数
Try remove =
and change exports
to export
only.尝试删除=
和改变exports
到export
而已。
function sum(a, b) => a + b
export { sum }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.