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

React Expo Android构建报错:TypeError: (0 , sourceMapString_1.default) 不是函数

解决Expo Android构建报错:TypeError: (0 , sourceMapString_1.default) is not a function

问题描述

Android构建过程中抛出如下错误:

[stderr]
TypeError: (0 , sourceMapString_1.default) is not a function
Thu, 08 Aug 2024 20:17:02 GMT
[stderr]
at /home/expo/workingdir/build/node_modules/@expo/metro-config/build/serializer/withExpoSerializers.js:98:55

已尝试升级/降级expo、metro-config、Android最低SDK版本及babel版本,均无法解决。此前配置相同的分支原本可正常构建,目前也出现相同报错。

项目package.json配置

{
  "name": "tagged-fe",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web",
    "preview-android": "eas build -p android --profile preview"
  },
  "dependencies": {
    "@expo-google-fonts/inter": "^0.2.3",
    "@expo/config-plugins": "^7.8.0",
    "@expo/metro-runtime": "~3.1.3",
    "@expo/prebuild-config": "^6.7.0",
    "@expo/webpack-config": "^19.0.0",
    "@react-native-async-storage/async-storage": "^1.21.0",
    "@react-navigation/material-top-tabs": "^6.6.6",
    "@react-navigation/native": "^6.1.7",
    "@react-navigation/native-stack": "^6.9.13",
    "@shopify/flash-list": "1.6.3",
    "axios": "^1.5.1",
    "babel-plugin-module-resolver": "^5.0.2",
    "expo": "~50.0.19",
    "expo-av": "~13.10.6",
    "expo-constants": "~15.4.6",
    "expo-contacts": "~12.8.2",
    "expo-dev-client": "~3.3.12",
    "expo-device": "~5.9.4",
    "expo-font": "~11.10.3",
    "expo-haptics": "~12.8.1",
    "expo-image": "~1.10.6",
    "expo-linking": "~6.2.2",
    "expo-notifications": "~0.27.8",
    "expo-sharing": "~11.10.0",
    "expo-splash-screen": "~0.26.5",
    "expo-status-bar": "~1.11.1",
    "link-preview-js": "^3.0.5",
    "lottie-react-native": "6.5.1",
    "metro-config": "^0.80.10",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-native": "0.73.6",
    "react-native-link-preview": "^1.4.2",
    "react-native-paper": "^5.10.4",
    "react-native-reanimated": "^3.14.0",
    "react-native-safe-area-context": "4.8.2",
    "react-native-screens": "~3.29.0",
    "react-native-tab-view": "^3.5.2",
    "react-native-toast-message": "^2.1.7",
    "react-native-web": "~0.19.6",
    "react-native-webview": "13.6.4",
    "recoil": "^0.7.7"
  },
  "devDependencies": {
    "@babel/core": "^7.25.2",
    "@types/react": "~18.2.14",
    "prettier": "^3.0.3",
    "typescript": "^5.1.3"
  },
  "private": true
}

解决方案

核心原因

你手动安装了metro-config@0.80.10,这是React Native 0.74+对应的版本,而你的项目使用的expo 50(~50.0.19)依赖的是@expo/metro-config@~0.17.x,两个版本不兼容导致sourceMapString导出方式不一致,触发报错。

修复步骤

  • 移除手动安装的metro-config依赖:修改package.json,删除"metro-config": "^0.80.10"这一行。
  • 清理并重新安装依赖:执行以下命令:
    rm -rf node_modules package-lock.json yarn.lock
    npm install
    
  • 临时禁用EAS Build缓存(若使用远程构建):在eas.json的对应profile中添加缓存禁用配置,确保构建环境拉取全新依赖:
    "preview": {
      "android": {
        "buildType": "apk"
      },
      "cache": {
        "disabled": true
      }
    }
    
    构建成功后可恢复缓存配置。
  • 验证本地构建:先在本地执行expo run:android测试是否能正常构建,确认无问题后再触发远程EAS Build。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 00:27:03