[英]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.