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

代理环境下yarn install安装optipng-bin失败求助

问题描述

本地构建环境已部署squid-deb-proxy代理,执行以下命令构建依赖:

yarn install --https-proxy=http://192.168.100.40:8000 --proxy=http://192.168.100.40:8000 --verbose

同时已在~/.npmrc中配置代理:

proxy=http://192.168.100.40:8000
https-proxy=http://192.168.100.40:8000
https_proxy=http://192.168.100.40:8000

构建时其他包均能正常通过代理下载,但optipng-bin编译失败,错误日志如下:

[4/4] Building fresh packages...
...
[4/5] ⠠ optipng-bin
verbose 23.465307382 ⚠ tunneling socket could not be established, cause=connect ENETUNREACH 0.0.31.64:80 - Local (0.0.0.0:0)
  ⚠ jpegtran pre-build test failed
  ℹ compiling from source
  ✖ RequestError: tunneling socket could not be established, cause=connect ENETUNREACH 0.0.31.64:80 - Local (0.0.0.0:0)
    at ClientRequest.<anonymous> (/opt/jenkinsagent/workspace/line_tmp-v34-jenkins-test-agent2/product/browser-phone/node_modules/got/index.js:111:21)
    at Object.onceWrapper (events.js:422:26)
    at ClientRequest.emit (events.js:315:20)
    at ClientRequest.onError (/opt/jenkinsagent/workspace/line_tmp-v34-jenkins-test-agent2/product/browser-phone/node_modules/tunnel-agent/index.js:179:21)
    at Object.onceWrapper (events.js:422:26)
    at ClientRequest.emit (events.js:315:20)
    at Socket.socketErrorListener (_http_client.js:469:9)
    at Socket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)

需要强制optipng-bin使用代理完成构建。

解决方法
  • 配置系统级环境变量
    optipng-bin的构建脚本可能优先读取系统环境变量,在执行yarn install前设置代理:

    export HTTP_PROXY=http://192.168.100.40:8000
    export HTTPS_PROXY=http://192.168.100.40:8000
    export NO_PROXY=localhost,127.0.0.1
    yarn install --verbose
    

    Windows环境替换为:

    set HTTP_PROXY=http://192.168.100.40:8000
    set HTTPS_PROXY=http://192.168.100.40:8000
    yarn install --verbose
    
  • 为optipng-bin单独配置代理
    通过npm配置命令为该包单独设置代理参数,确保其构建脚本能读取到:

    npm config set optipng-bin:proxy http://192.168.100.40:8000
    npm config set optipng-bin:https-proxy http://192.168.100.40:8000
    yarn install --verbose
    
  • 临时修改构建脚本
    若上述方法无效,可手动修改node_modules/optipng-bin/lib/install.js(安装失败后该文件已生成),在使用got发起请求的代码段中添加代理配置:

    // 在got请求的options中添加proxy字段
    const response = await got(url, {
      proxy: 'http://192.168.100.40:8000',
      // 保留原有其他配置
    });
    

    修改后重新执行yarn install --verbose。

  • 切换代理镜像源
    若代理仍无法生效,可将npm/yarn registry切换到国内镜像,直接获取预编译包:

    yarn config set registry https://registry.npmmirror.com
    yarn install --verbose
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 17:24:18