简体   繁体   English

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

[英]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.尝试删除=和改变exportsexport而已。

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

export { sum }

暂无
暂无

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

相关问题 获取不能在 node.js 中的模块外使用导入语句 - Get Cannot use import statement outside a module in node.js Node.js:语法错误:无法在模块外使用导入语句 - Node.js: SyntaxError: Cannot use import statement outside a module 无法在 node.js 中的模块外使用 import 语句 - Cannot use import statement outside a module in node.js SyntaxError:无法在 node.js 上的模块外部使用 import 语句 - SyntaxError: Cannot use import statement outside a module on node.js 未捕获的语法错误:无法在节点 js 中的模块外使用导入语句 - Uncaught SyntaxError: Cannot use import statement outside a module in node js Jest with TypeScript (Backend - Node/Express) 说 Cannot use import statement outside a module - Jest with TypeScript (Backend - Node/Express) says Cannot use import statement outside a module node-fetch 3.0.0 和 jest 给出了 SyntaxError:不能在模块外使用导入语句 - node-fetch 3.0.0 and jest gives SyntaxError: Cannot use import statement outside a module Jest 或 Mocha 与 Vue:SyntaxError:无法在模块外使用 import 语句 - Jest or Mocha with Vue: SyntaxError: Cannot use import statement outside a module 开玩笑的单元测试 - SyntaxError:不能在模块外使用 import 语句 - Jest unit test - SyntaxError: Cannot use import statement outside a module 如何在玩笑中解决“SyntaxError: Cannot use import statement outside a module” - How to resolve "SyntaxError: Cannot use import statement outside a module" in jest
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM