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

使用react-app-rewired build构建TSX React项目遇解析错误

React + TSX项目使用react-app-rewired build构建失败,提示Module parse failed: Unexpected token

使用react-app-rewired build命令构建基于TSX的React应用时,出现以下构建错误:

Module parse failed: Unexpected token (256:123)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
* ./node_modules/source-map-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
|  *     not null.
|  */
> var gen_bitlen = function gen_bitlen(s, desc) /*    deflate_state *s;*/ /*    tree_desc *desc;    /* the tree descriptor */*/{
|   var tree = desc.dyn_tree;
|   var max_code = desc.max_code;

环境信息

% node -v
v14.19.1
% npm -v
8.19.3
% yarn -v
1.22.19

tsconfig.json配置

{
  "compilerOptions": {
    "noImplicitAny": false,
    /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
    "target": "es2019",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "noFallthroughCasesInSwitch": true,
    "jsx": "react-jsx",
    "baseUrl": "./src"
  },
  "include": ["src", "internals/startingTemplate/**/*"],
  "ts-node": {
    "compilerOptions": {
      "esModuleInterop": true,
      "module": "commonjs",
      "moduleResolution": "node",
      "noEmit": true,
      "allowSyntheticDefaultImports": true,
      "types": [
        "node"
      ]
    }
  }
}

我没有主动更新任何依赖包,但发现@babel相关库已经自动更新到v7.20.2(该版本21小时前刚发布),推测这次构建失败可能和这个版本更新有关,想问问有没有其他人遇到过相同的问题?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 19:01:03