简体   繁体   中英

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

You should be able to reproduce the same error by run 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. 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. Took me a while to figure it out! Hope someone finds it helpful!

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

Enjoy!

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