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

CRA项目集成mui-color-input后Jest测试报模块语法错误

CRA项目引入mui-color-input后Jest测试报错问题

我在create-react-app(CRA)项目中引入了mui-color-input库,项目构建正常,但执行组件测试时遇到Jest错误:

● Test suite failed to run

Jest encountered an unexpected token

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

node_modules/mui-color-input/dist/mui-color-input.es.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { jsx as c, jsxs as lt, Fragment as Mt } from "react/jsx-runtime";
^^^^^^

SyntaxError: Cannot use import statement outside a module

&gt; 26 | import { MuiColorInput } from "mui-color-input";
     | ^
  27 |

以下是package.json中的依赖列表:

"dependencies": {
    "@emotion/react": "^11.11.1",
    "@emotion/styled": "^11.11.0",
    "@mui/icons-material": "^5.14.3",
    "@mui/lab": "^5.0.0-alpha.140",
    "@mui/material": "^5.14.5",
    "@mui/styles": "^5.14.5",
    "mui-color-input": "^2.0.0",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-scripts": "5.0.1"
  },
  "devDependencies": {
    "@babel/plugin-proposal-private-property-in-object": "^7.21.11",
    "@testing-library/jest-dom": "5.14.1",
    "@testing-library/react": "14.0.0",
    "@testing-library/user-event": "13.2.1",
    "@types/jest": "27.0.1",
    "@types/node": "16.7.13",
    "@types/react": "18.0.0",
    "@types/react-dom": "18.0.0",
    "@types/react-test-renderer": "^16.9.1",
    "jest-junit": "^10.0.0",
    "prettier": "^1.19.1",
    "react-test-renderer": "^16.12.0",
    "typescript": "4.4.2"
  },

我查阅了同类问题的相关帖子,这类错误通常与导入语句错误有关,但根据该库官方文档,我的导入语句是正确的。我最初认为可能是测试库版本过时导致问题,但该错误仅出现在这个特定的导入语句中,且更新@testing-library/react等部分包后,问题仍未解决。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 07:30:20