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

Linux服务器上Electron npm包安装失败问题求助

问题描述

在Linux服务器执行npm install electron安装Electron npm包时失败,报错信息如下:

# npm install electron
npm ERR! code 1
npm ERR! path /home/json-app/node_modules/electron
npm ERR! command failed
npm ERR! command sh -c -- node install.js
npm ERR! RequestError: getaddrinfo ENOTFOUND github.com
npm ERR!     at ClientRequest.<anonymous> (/home/jsonapp/node_modules/got/dist/source/core/index.js:970:111)
npm ERR!     at Object.onceWrapper (node:events:628:26)
npm ERR!     at ClientRequest.emit (node:events:525:35)
npm ERR!     at ClientRequest.origin.emit (/home/jsonapp/code/POC/json-app/node_modules/@szmarczak/http-timer/dist/source/index.js:43:20)
npm ERR!     at TLSSocket.socketErrorListener (node:_http_client:494:9)
npm ERR!     at TLSSocket.emit (node:events:513:28)
npm ERR!     at emitErrorNT (node:internal/streams/destroy:157:8)
npm ERR!     at emitErrorCloseNT (node:internal/streams/destroy:122:3)
npm ERR!     at processTicksAndRejections (node:internal/process/task_queues:83:21)
npm ERR!     at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:109:26)

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-09-15T07_19_23_981Z-debug-0.log

问题原因

报错中的getaddrinfo ENOTFOUND github.com是核心问题:服务器无法解析github.com的域名,DNS解析失败导致Electron的安装脚本无法从GitHub下载所需的二进制包,最终安装终止。

解决办法

1. 排查DNS解析问题

  • 先测试服务器能否连通github.com:
    ping github.com
    
  • 如果ping不通,修改DNS配置:
    • 查看当前DNS配置:cat /etc/resolv.conf
    • 手动添加公共DNS服务器(比如谷歌或Cloudflare的DNS),编辑/etc/resolv.conf添加:
      nameserver 8.8.8.8
      nameserver 1.1.1.1
      
    • 保存后重新测试连通性,再执行安装命令

2. 切换到国内Electron镜像源

如果DNS问题无法快速解决,或者国内网络访问GitHub受限,可使用国内镜像源绕开:

  • 临时使用镜像安装:
    npm install electron --registry=https://registry.npmmirror.com --electron_mirror=https://npmmirror.com/mirrors/electron/
    
  • 全局配置镜像源,后续无需重复指定:
    npm config set registry https://registry.npmmirror.com
    npm config set electron_mirror https://npmmirror.com/mirrors/electron/
    npm install electron
    

3. 检查防火墙与代理设置

  • 确认服务器防火墙未拦截github.com的访问请求
  • 如果服务器使用代理,配置npm代理:
    npm config set proxy http://你的代理地址:端口
    npm config set https-proxy http://你的代理地址:端口
    
  • 安装完成后如需取消代理,执行:
    npm config delete proxy
    npm config delete https-proxy
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 01:32:07