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

Expo SDK48开发客户端返回无法解析的Manifest问题求助

解决Expo开发客户端解析Manifest的格式错误问题

问题现象

执行npx expo start --dev-client后,Android和iOS开发客户端连接开发服务器时均触发解析错误:

  • Android端:Error loading app. Value ----------------------------224819657222108214122421 of type java.lang.String cannot be converted to JSONObject
  • iOS端:Error loading app. Couldn't parse the manifest. The data couldn't be read because it isn't in the correct format

手动访问开发服务器地址(如http://192.168.1.179:8081),返回的Manifest是带分隔符的multipart/form-data格式(包含表单元数据),而非开发客户端预期的纯JSON格式,示例如下:

----------------------------783506567945418080873744
Content-Disposition: form-data; name="manifest"
Content-Type: application/json

{"id":"203368a8-dcbe-45a6-afba-0a1e76018e5d","createdAt":"2023-08-24T06:02:54.108Z","runtimeVersion":"1.0.6","launchAsset":{"key":"bundle","contentType":"application/javascript","url":"http://192.168.1.179:8081/index.bundle?platform=none&dev=true&hot=false"},"assets":[],"metadata":{},"extra":{"eas":{"projectId":"cc2c7913-15b1-4e18-aa87-a29294e12ac9"},"expoClient":...............,"packagerOpts":{"dev":true},"mainModuleName":"index","__flipperHack":"React Native packager is running"},"scopeKey":"@speciesplus/speciesplus"}}
----------------------------783506567945418080873744--

环境背景:

  • Expo托管项目,使用npx expo prebuild --clean生成原生文件
  • 本地构建(Android Studio 2022.3.1、Xcode 14.2)或EAS本地构建(配置如下)均触发相同错误:
"development": {
  "developmentClient": true,
  "distribution": "internal",
  "channel": "development",
  "android": {
    "buildType": "apk"
  }
}
  • 技术栈:expo@48.0.18、react@18.2.0、react-native@0.71.8、node@16.18.1、react-native-code-push@7.1.0(已打补丁)

解决方案

1. 排查CodePush补丁与配置

问题根源大概率是react-native-code-push的适配补丁修改了Metro服务器的Manifest输出格式,将纯JSON改为了multipart/form-data:

  • 临时移除CodePush相关依赖及补丁,执行npx expo prebuild --clean后重新测试。若恢复正常,说明补丁存在格式兼容问题。
  • 检查CodePush补丁中是否有修改Metro响应头或输出内容的逻辑,确保Manifest返回时的Content-Type为application/json,且仅输出纯JSON数据。

2. 修正Metro服务器响应格式

在metro.config.js中添加中间件,拦截Manifest请求并提取纯JSON内容返回:

const { getDefaultConfig } = require('@expo/metro-config');
const config = getDefaultConfig(__dirname);

// 拦截Manifest请求,修正响应格式
config.server.middleware = (req, res, next) => {
  if (req.url === '/' || req.url.startsWith('/manifest')) {
    const originalSend = res.send;
    res.send = function(data) {
      // 检测是否为multipart格式,提取JSON部分
      if (typeof data === 'string' && data.startsWith('---------------------------')) {
        const jsonStartIndex = data.indexOf('{"id"');
        const jsonEndIndex = data.lastIndexOf('}') + 1;
        const pureJson = data.slice(jsonStartIndex, jsonEndIndex);
        res.setHeader('Content-Type', 'application/json');
        originalSend.call(this, pureJson);
      } else {
        originalSend.call(this, data);
      }
    };
  }
  next();
};

module.exports = config;

3. 重置开发环境

  • 清理Metro缓存:npx expo start --clear
  • 重新生成原生文件:npx expo prebuild --clean
  • 重新构建开发客户端(本地或EAS构建),确保使用最新配置。

4. 验证修复效果

重启Metro服务器后,手动访问服务器地址,确认返回内容为纯JSON格式的Manifest,再用开发客户端连接测试,确认错误消失。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 10:07:23