简体   繁体   English

开玩笑的返回错误:SyntaxError:“导入”和“导出”可能仅与“ sourceType:“模块””一起出现(21:0)

[英]jest return ERROR: SyntaxError: 'import' and 'export' may appear only with 'sourceType: “module”' (21:0)

I have a demo repo setup already https://github.com/adamchenwei/jest-playground 我已经有一个演示回购设置https://github.com/adamchenwei/jest-playground

You should be able to reproduce the same error by run npm run test 您应该能够通过运行npm run test重现相同的错误

在此处输入图片说明

Not really sure what is causing it, any idea how to debugging further on this? 不太确定是什么原因引起的,是否知道如何对此进行进一步调试? I already minimize the code in the component, but for some reason, jest still failing with that little bit code. 我已经最小化了组件中的代码,但是由于某种原因,开玩笑仍然用那一点点代码失败了。 I haven't even be able to get into the problem with image loading yet lol 我什至无法解决图片加载问题

Found the issue. 找到了问题。 Actually, it had wrong babel setup. 实际上,它的babel设置错误。 That's why its throwing that error! 这就是为什么它会抛出该错误!

I fixed the issue in this commit, check it out! 我已在此提交中修复了该问题,请查看! adding the missing babel config in package.json and updated babel deps. 在package.json中添加缺少的babel配置并更新babel deps。 Took me a while to figure it out! 花了我一段时间才弄清楚! Hope someone finds it helpful! 希望有人觉得有帮助!

https://github.com/adamchenwei/jest-playground/commit/ed2d635b779fab52876069f53584aaa48a9c66a7 https://github.com/adamchenwei/jest-playground/commit/ed2d635b779fab52876069f53584aaa48a9c66a7

Enjoy! 请享用!

暂无
暂无

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

相关问题 SyntaxError: 'import' 和 'export' 可能只与 'sourceType: module' 一起出现 - Gulp - SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' - Gulp cypress + lerna: ParseError: 'import' 和 'export' 可能只出现在 'sourceType: module' 中 - cypress + lerna: ParseError: 'import' and 'export' may appear only with 'sourceType: module' Cypress ParseError: 'import' 和 'export' 可能只出现在 'sourceType: module' - Cypress ParseError: 'import' and 'export' may appear only with 'sourceType: module' 'import' 和 'export' 只能与 'sourceType: "module"' 一起出现 (16:0) - 'import' and 'export' may appear only with 'sourceType: "module"' (16:0) ParseError: 'import' 和 'export' 可能只出现在 'sourceType: module', browserify - ParseError: 'import' and 'export' may appear only with 'sourceType: module', browserify create-react-app eslint 错误“解析错误:‘import’和‘export’可能只出现在‘sourceType:module’中” - create-react-app eslint error "Parsing error: 'import' and 'export' may appear only with 'sourceType: module'" NPM + Browserify 错误:ParseError: 'import' 和 'export' 可能只出现在 'sourceType: module' 中 - NPM + Browserify error: ParseError: 'import' and 'export' may appear only with 'sourceType: module' Browserify Rails错误-ParseError:“导入”和“导出”可能仅与“ sourceType:模块”一起出现 - Browserify Rails Error - ParseError: 'import' and 'export' may appear only with 'sourceType: module' 如何告诉 eslint:禁用下一行“'import'和'export'可能只与'sourceType:module'一起出现” - How to tell eslint to: disable next line "'import' and 'export' may appear only with 'sourceType: module'" Babel 7 不转译 node_modules 中的依赖项:'import' 和 'export' 可能只与 'sourceType: module' 一起出现 - Babel 7 not transpiling dependencies in node_modules: 'import' and 'export' may appear only with 'sourceType: module'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM