简体   繁体   中英

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

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

then I got error of SyntaxError: Cannot use import statement outside a module

I'm using node v12, what's the problem here? I don't want to use export defaults because I have more than 1 function inside index.js

Try remove = and change exports to export only.

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

export { sum }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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