Expo环境安装react-native-mmkv后构建时pod install失败求助
问题重现
在Expo项目中安装react-native-mmkv,执行npx expo prebuild后,运行npx expo run:ios时触发以下错误:
⚠️ 在
ios目录中运行pod install时出错。
命令pod install执行失败。
└─ 原因:安装MMKVCore出错
[!] /usr/local/bin/git clone https://github.com/Tencent/MMKV.git /var/folders/v6/8yrsb82d0j1ckkc8dccwm70c0000gn/T/d20240711-4366-2smlq1 --template= --single-branch --depth 1 --branch v1.3.7正在克隆到'/var/folders/v6/8yrsb82d0j1ckkc8dccwm70c0000gn/T/d20240711-4366-2smlq1'...
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
error: 3689 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
解决方案
这个错误本质是git克隆MMKV仓库时的网络传输中断,可按以下步骤逐一尝试:
增大git网络传输限制
终端执行以下命令提升git的网络参数:git config --global http.postBuffer 524288000 git config --global http.maxRequestBuffer 100M git config --global core.compression 0之后重新运行
npx expo run:ios。手动克隆MMKV并让pod指向本地路径
- 在本地任意目录克隆指定版本的MMKV仓库:
git clone --single-branch --depth 1 --branch v1.3.7 https://github.com/Tencent/MMKV.git - 打开项目的
ios/Podfile,找到MMKVCore的依赖配置,替换为本地克隆路径(示例路径为~/Documents/MMKV):pod 'MMKVCore', :path => '~/Documents/MMKV' - 进入ios目录执行
pod install,再回到项目根目录运行npx expo run:ios。
- 在本地任意目录克隆指定版本的MMKV仓库:
清理缓存后重试
执行以下命令清理Expo和pod的缓存:npx expo prebuild --clean rm -rf ios/Pods ios/Podfile.lock pod cache clean --all重新执行
npx expo prebuild和npx expo run:ios。切换网络环境
如果当前网络不稳定,尝试切换到其他网络(比如手机热点),同时检查是否有代理、防火墙阻止了git的HTTPS请求。
内容的提问来源于stack exchange,提问作者Web_Dev_Ary

