繁体   English   中英

不能使用 jest 在模块 node.js 之外使用 import 语句

[英]Cannot use import statement outside a module node.js using jest

我在 index.js function sum(a, b) => a + b exports = { sum }和 index.spec.js 中有这个

import { sum } from './index.js'

然后我得到了SyntaxError: Cannot use import statement outside a module错误SyntaxError: Cannot use import statement outside a module

我正在使用 node v12,这里有什么问题? 我不想使用export defaults因为我在 index.js 中有超过 1 个函数

尝试删除=和改变exportsexport而已。

function sum(a, b) => a + b

export { sum }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM