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

升级Expo v47后EAS iOS构建失败:无法加载colored2文件

解决Expo v47升级后iOS EAS构建报错“cannot load such file -- colored2”的问题

问题描述

将Expo项目升级到v47后,使用eas build -p ios --local命令进行本地iOS构建(云端构建同样失败),触发如下错误:

[INSTALL_PODS] [!] Invalid Podfile file: cannot load such file -- colored2.
[INSTALL_PODS] # from /private/var/folders/yr/7xc177dn2cz107wsvzg573_m0000gn/T/eas-build-local-nodejs/c132d044-2136-499b-9471-1b0e11438b09/build/React/ios/Podfile:1
[INSTALL_PODS] # -------------------------------------------
[INSTALL_PODS] > require File.join(File.dirname(node --print \"require.resolve('expo/package.json')\"), "scripts/autolinking")
[INSTALL_PODS] # require File.join(File.dirname(node --print \"require.resolve('react-native/package.json')\"), "scripts/react_native_pods")
[INSTALL_PODS] # -------------------------------------------

项目在Expo Go中可正常运行,但expo doctor检测到依赖版本不匹配:

Expected package @expo/config-plugins@^5.0.2
Found invalid:
@expo/config-plugins@5.0.1
@expo/config-plugins@4.1.5
(for more info, run: npm why @expo/config-plugins)
Expected package @expo/prebuild-config@^5.0.5
Found invalid:
@expo/prebuild-config@5.0.3
(for more info, run: npm why @expo/prebuild-config)

解决方案

1. 修复依赖版本不匹配

  • 删除项目根目录下的node_modules文件夹、package-lock.json(或yarn.lock)文件
  • 安装指定版本的依赖包:
    npm install @expo/config-plugins@^5.0.2 @expo/prebuild-config@^5.0.5 --save-exact
    
    若使用Yarn则执行:
    yarn add @expo/config-plugins@^5.0.2 @expo/prebuild-config@^5.0.5 --exact
    
  • 重新运行expo doctor确认依赖问题已解决

2. 清除构建缓存

  • 本地构建:执行带清理参数的构建命令,或手动删除报错中显示的临时构建目录
    eas build --clean -p ios --local
    
  • 云端构建:在EAS构建控制台开启「清除缓存」选项后重新发起构建

3. 重新生成iOS构建配置

如果上述步骤无效,重新生成Podfile及iOS目录配置:

npx expo prebuild --clean

注意:此命令会覆盖ios目录内容,若有自定义修改请先备份。

原因说明

升级Expo v47后,项目中@expo/config-plugins和@expo/prebuild-config版本不匹配,导致Expo autolinking脚本(Podfile中引用的scripts/autolinking)无法正确加载其依赖的Ruby包colored2,进而触发Podfile解析错误。虽然项目未直接引用colored2,但它是Expo构建流程的间接依赖包,统一依赖版本后即可解决问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 02:50:22