如何解决expo-cli请求实体过大(request entity too large)问题?
解决Expo EAS构建后安卓传输包时的PayloadTooLargeError问题
问题描述
每次执行yarn start启动Expo项目,安卓设备尝试上传并启动应用时,抛出以下错误:
Android Bundling complete 288ms AsyncStorage has been extracted from react-native core and will be removed in a future release. It can now be installed and imported from '@react-native-async-storage/async-storage' instead of 'react-native'. See https://github.com/react-native-async-storage/async-storage PayloadTooLargeError: request entity too large at readStream (/usr/local/lib/node_modules/expo-cli/node_modules/raw-body/index.js:155:17) at getRawBody (/usr/local/lib/node_modules/expo-cli/node_modules/raw-body/index.js:108:12) at read (/usr/local/lib/node_modules/expo-cli/node_modules/body-parser/lib/read.js:77:3) at jsonParser (/usr/local/lib/node_modules/expo-cli/node_modules/body-parser/lib/types/json.js:135:5) at call (/home/mathieu_auclair/Documents/Coinmiles/repositories/mobile/node_modules/connect/index.js:239:7) at next (/home/mathieu_auclair/Documents/Coinmiles/repositories/mobile/node_modules/connect/index.js:183:5) at remoteDevtoolsCorsMiddleware (/usr/local/lib/node_modules/expo-cli/node_modules/@expo/dev-server/src/middleware/remoteDevtoolsCorsMiddleware.ts:31:3) at call (/home/mathieu_auclair/Documents/Coinmiles/repositories/mobile/node_modules/connect/index.js:239:7) at next (/home/mathieu_auclair/Documents/Coinmiles/repositories/mobile/node_modules/connect/index.js:183:5) at serveStatic (/home/mathieu_auclair/Documents/Coinmiles/repositories/mobile/node_modules/serve-static/index.js:75:16) › Stopped server Done in 378.28s.
已尝试升级/降级expo-cli版本,无效;问题自迁移到Expo EAS构建系统后出现。
解决方法
调整开发服务器请求体大小限制:在项目根目录的
expo.config.js(无则新建)中添加devServer配置,增大请求体上限:module.exports = { // 其他项目配置 devServer: { bodyParser: { json: { limit: '10mb' }, // 根据实际包体积调整,如20mb }, }, };修改后重启
yarn start测试。优化构建包体积:
- 清理项目中未使用的依赖、冗余图片/字体资源
- 在
eas.json中开启安卓构建的压缩与混淆:{ "build": { "production": { "android": { "minifyEnabled": true, "proguardEnabled": true } } } } - 将图片转为WebP格式,压缩资源体积
切换调试模式:调试阶段暂时使用Expo Go本地构建替代EAS自定义包,执行
expo prebuild --clean重置本地配置后,重新用yarn start启动选择Expo Go模式。优化网络连接:确保设备与开发电脑在同一局域网,尝试使用USB调试模式下的网络共享,提升传输稳定性。
内容的提问来源于stack exchange,提问作者MathieuAuclair
相关产品推荐
相关产品推荐

