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

Expo CLI报错:无法找到yarn-1.22.19.cjs模块求助

解决EAS Build中Yarn模块找不到的问题

问题场景

已弹出的Expo 46.0.9 React Native应用处于NX monorepo中(未通过project.json关联),此前执行eas build --profile preview --platform android/ios可正常构建,现在报错找不到指定Yarn版本文件:

Error: Cannot find module '/home/expo/workingdir/build/.yarn/releases/yarn-1.22.19.cjs'

解决方法

1. 确保Yarn版本文件已提交到Git

构建环境找不到文件,大概率是.yarn/releases目录被Git忽略了:

  • 打开项目根目录的.gitignore,检查是否包含.yarn/releases,如果有则移除该行
  • 提交Yarn版本文件到仓库:
    git add .yarn/releases/yarn-1.22.19.cjs
    git commit -m "Track Yarn release file in repo"
    git push
    

2. 调整EAS Build的工作目录

由于应用在monorepo子目录,默认构建目录可能找不到根目录的Yarn配置,在eas.json的preview配置中指定工作目录为monorepo根:

{
  "build": {
    "preview": {
      "workingDirectory": "../..",
      "android": { /* 原有配置 */ },
      "ios": { /* 原有配置 */ }
    }
  }
}

3. 强制EAS安装指定Yarn版本

如果不想提交.yarn目录,可通过配置让EAS自动安装对应版本:

  • 在项目根目录package.json中添加:
    {
      "packageManager": "yarn@1.22.19"
    }
    
  • 或者构建时通过环境变量指定:
    eas build --profile preview --platform android --env YARN_VERSION=1.22.19
    

4. 校验Yarn路径配置

检查项目根目录.yarnrc中的yarn-path是否正确指向存在的文件:

yarn-path ".yarn/releases/yarn-1.22.19.cjs"

如果路径错误,修正后提交到仓库。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 14:27:45