EAS Expo开发构建无法加载应用,生产与模拟器构建正常
EAS开发客户端构建启动报错排查方案(iOS MIME类型错误/Android加载脚本失败)
问题背景
从Expo经典构建迁移至EAS,使用managed workflow(自定义开发客户端),环境为eas-cli/3.6.1 darwin-x64 node-v19.6.1、Expo 47版本。目前iOS模拟器构建、TestFlight生产构建均正常,但development构建成功后,iOS/Android真机启动时闪屏后进入错误界面:
- iOS错误:
Expected MIME-Type to be 'application/javascript' or 'text/javascript', but got 'text/html'. - Android错误:
Unable to load script. Make sure you're either running Metro or that your bundle 'index.android.bundle' is packaged correctly for release
当前eas.json配置:
{ "cli": { "version": ">= 3.6.1" }, "build": { "development": { "developmentClient": true, "distribution": "internal", "channel": "development", "ios": { "resourceClass": "m1-medium" } }, "simulator": { "distribution": "internal", "channel": "simulator", "ios": { "simulator": true, "resourceClass": "m1-medium" } }, "production": { "channel": "production", "ios": { "resourceClass": "m1-medium" } } }, "submit": { "production": {} } }
排查方向
确认Metro服务连接状态
开发客户端依赖本地Metro服务加载JS代码,启动App前必须确保:- Metro正在运行(执行
expo start --channel development,匹配eas.json中指定的development渠道) - 真机与电脑处于同一局域网,或使用
expo start --tunnel通过隧道连接 - Android端执行
adb reverse tcp:8081 tcp:8081确保端口转发正常;iOS端检查开发者证书是否已信任,且Metro的IP地址配置正确
- Metro正在运行(执行
检查development构建的bundle加载逻辑
当前eas.json的development配置未明确离线打包逻辑,开发客户端默认尝试加载远程Metro服务,若服务不可达会返回HTML错误页(对应iOS的MIME类型错误):- 尝试在development配置中添加
offlineBundle: true,强制构建时打包本地bundle(仅用于测试,开发模式推荐在线加载) - 确认
app.json中expo.developmentClient.enabled已设为true,且包名/ bundleIdentifier与构建配置一致
- 尝试在development配置中添加
验证渠道(channel)发布状态
若开发客户端配置了渠道,会优先加载对应渠道的远程发布包:- 执行
expo publish --channel development,确保该渠道有正常发布的JS bundle,避免因发布失败返回HTML错误 - 启动Metro时必须指定对应渠道(
expo start --channel development),否则客户端会尝试加载错误的资源
- 执行
清理构建缓存与依赖
旧缓存或依赖冲突可能导致打包异常:- 执行
eas build --clear-cache清理EAS远程构建缓存 - 本地执行
rm -rf node_modules package-lock.json && npx expo install修复依赖 - iOS端清理Xcode的DerivedData,Android端执行
./gradlew clean清理本地构建缓存
- 执行
检查Metro与项目入口配置
- 确认
metro.config.js无错误配置(如错误的assetExts/sourceExts),确保Metro能正确识别JS文件 - 检查项目根目录的
index.js/App.js入口文件存在且无语法错误,Metro启动时无报错 - iOS端检查
Info.plist的NSAppTransportSecurity配置,允许localhost的HTTP连接(开发环境需关闭ATS限制)
- 确认
内容的提问来源于stack exchange,提问作者Behnam Kamrani
相关产品推荐
相关产品推荐

