GitLab CI/CD中Symfony项目Yarn依赖安装失败求助
问题描述
在GitLab CI/CD构建Symfony项目时,Yarn安装依赖阶段出现网络连接错误,无法解析Yarn仓库地址。CI环境已配置公司代理,但问题依旧。以下是CI日志:
$ rm yarn.lock $ yarn --version 1.22.5 $ yarn config set cache-folder .yarn yarn config v1.22.5 success Set "cache-folder" to ".yarn". Done in 0.03s. $ yarn config set proxy-http http://<username>:<password>@<url>:<port> yarn config v1.22.5 success Set "proxy-http" to "http://<username>:<password>@<url>:<port>". Done in 0.04s. $ yarn config set proxy-https-proxy http://<username>:<password>@<url>:<port> yarn config v1.22.5 success Set "proxy-https-proxy" to "http://<username>:<password>@<url>:<port>". Done in 0.04s. $ yarn install --network-timeout=1000000 yarn install v1.22.5 info No lockfile found. warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json. [1/4] Resolving packages... info There appears to be trouble with your network connection. Retrying... info There appears to be trouble with your network connection. Retrying... info There appears to be trouble with your network connection. Retrying... info There appears to be trouble with your network connection. Retrying... info If you think this is a bug, please open a bug report with the information provide in "/builds/eirel/eirel-app/yarn-error.log". info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. error An unexpected error occurred: "https://registry.yarnpkg.com/@fortawesome%2ffontawesome-free: getaddrinfo ENOTFOUND registry.yarnpkg.com registry.yarnpkg.com:443".
解决方案
1. 修正Yarn代理配置参数
你当前使用的代理参数名错误,Yarn的正确代理配置参数是proxy(对应HTTP代理)和https-proxy(对应HTTPS代理),而非proxy-http和proxy-https-proxy。修改CI中的配置命令:
yarn config set proxy http://<username>:<password>@<url>:<port> yarn config set https-proxy http://<username>:<password>@<url>:<port>
2. 移除冲突的锁文件
日志提示存在package-lock.json,这是npm生成的锁文件,和Yarn的yarn.lock会导致依赖解析冲突。在CI步骤中添加移除命令:
rm -f package-lock.json
3. 配置系统级代理环境变量(可选)
如果Yarn配置代理仍不生效,可以在CI环境中设置系统级的代理环境变量,Yarn会自动读取这些变量:
export HTTP_PROXY=http://<username>:<password>@<url>:<port> export HTTPS_PROXY=http://<username>:<password>@<url>:<port> export NO_PROXY=localhost,127.0.0.1
4. 验证代理连通性
在CI步骤中添加连通性测试,确认代理能正常访问Yarn仓库:
curl -x http://<username>:<password>@<url>:<port> https://registry.yarnpkg.com
如果测试失败,需要检查代理地址、端口、用户名密码是否正确,以及CI runner是否有权限访问代理服务器。
内容的提问来源于stack exchange,提问作者nboulfroy
相关产品推荐
相关产品推荐

