You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用create-react-app与Jest执行测试时遇SyntaxError: Unexpected token import错误

解决Create React App中Jest测试的SyntaxError: Unexpected token import问题

最近用create-react-app开发项目时,Jest测试突然卡壳了——只要在测试文件里导入任意React组件,运行yarn test后测试套件直接跑不起来,报错指向.../src/node_modules/common/ErrorMessage.js的第1行,错误类型是SyntaxError: Unexpected token import。

折腾了一阵后,我找到了可行的解决办法,亲测有效:

  • 将src/node_modules文件夹内的所有代码迁移至src目录的根路径下
  • 迁移完成后,删除src/node_modules文件夹

这个解决思路来自GitHub上的create-react-app官方社区讨论。

内容的提问来源于stack exchange,提问作者haiba

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:38:00