docmirror/dev-sidecar · warning
设置windows系统代理失败:执行
Error message
设置windows系统代理失败:执行
What it means
Warning logged in the Windows system-proxy setter when the primary mechanism, the native module `@starknt/sysproxy` (triggerManualProxyByUrl), throws. The code logs this warning and retries via the bundled `sysproxy.exe global <addr> <exclude>` executable. If the exe also fails (e2), the original sysproxy exception (e1) is re-thrown and the proxy setup fails.
Source
Thrown at packages/core/src/shell/scripts/set-system-proxy/index.js:475
loadConfig()
log.info('开始设置windows系统代理:', ip, port, setEnv)
// https
let proxyAddr = `https=http://${ip}:${port}`
// http
if (config.get().proxy.proxyHttp) {
proxyAddr = `http=http://${ip}:${port - 1};${proxyAddr}`
}
// 读取排除域名
const excludeIpStr = getProxyExcludeIpStr(';')
// 设置代理,同时设置排除域名
try {
require('@starknt/sysproxy').triggerManualProxyByUrl(true, proxyAddr, excludeIpStr, true)
log.info(`设置windows系统代理成功: ${proxyAddr} ......(省略排除IP列表)`)
} catch (e1) {
log.warn('设置windows系统代理失败:执行 `@starknt/sysproxy` 失败,现尝试通过执行 `sysproxy.exe global ...` 来设置系统代理!\r\n捕获的异常:', e1)
const proxyPath = extraPath.getProxyExePath()
const execFun = 'global'
try {
await execFile(proxyPath, [execFun, proxyAddr, excludeIpStr])
log.info(`设置windows系统代理成功,执行的命令:${proxyPath} ${execFun} ${proxyAddr} ......(省略排除IP列表)`)
} catch (e2) {
log.error(`设置windows系统代理失败,执行的命令:${proxyPath} ${execFun} ${proxyAddr} ......(省略排除IP列表), error:`, e2)
throw e1 // 将上面的异常抛出
}
}
if (setEnv) {
// 设置全局代理所需的环境变量
try {
await exec(`echo '设置环境变量 HTTPS_PROXY${config.get().proxy.proxyHttp ? '、HTTP_PROXY' : ''}${setCaBundle ? '、REQUEST_CA_BUNDLE' : ''}'`)
log.info(`开启系统代理的同时设置环境变量:HTTPS_PROXY = "http://${ip}:${port}/"`)View on GitHub (pinned to 7710cd56cc)
Solutions
- Check the logged captured exception (e1) for NODE_MODULE_VERSION/ABI mismatch; run `pnpm rebuild @starknt/sysproxy` or reinstall node_modules so the native module matches the running Node/Electron
- Confirm sysproxy.exe exists next to the app (extraPath.getProxyExePath()) and is not blocked by antivirus; re-run the installer if missing
- Run the app in a normal interactive user session (not a service), and verify manual proxy works: Settings > Network > Proxy should show the address after enabling
- If the native module remains incompatible with your platform, set the Windows proxy manually or disable automatic system-proxy in DevSidecar config
Example fix
// before (native module ABI mismatch after Electron upgrade)
require('@starknt/sysproxy').triggerManualProxyByUrl(true, proxyAddr, excludeIpStr, true)
// Error: NODE_MODULE_VERSION mismatch
// after — rebuild native deps against the current runtime
pnpm install
pnpm rebuild @starknt/sysproxy Defensive patterns
Strategy: try-catch
Validate before calling
function sysproxyModuleUsable() {
try {
const sysproxy = require('@starknt/sysproxy')
return typeof sysproxy.triggerManualProxyByUrl === 'function'
} catch (e) {
console.warn('@starknt/sysproxy unavailable:', e.message)
return false
}
} Try / catch
try {
await DevSidecar.api.config.set('proxy.enable', true)
} catch (e) {
console.error('Windows system proxy could not be set (both sysproxy paths failed):', e.message)
// fallback: set proxy manually via Settings > Network > Proxy
} Prevention
- Rebuild native modules after every Node/Electron version change (pnpm rebuild)
- Keep sysproxy.exe present and allowlisted in antivirus next to the app
- Run the app in an interactive user session, not as a Windows service
- Verify proxy takes effect in Settings > Network > Proxy after enabling
When it happens
Trigger: Called during executor.windows() on enabling the system proxy. Triggers: @starknt/sysproxy native binding fails to load or call (wrong Node ABI/electron rebuild mismatch, missing DLL, unsupported Windows), or WinHTTP/WinINET call rejected (WinInet not available in service session).
Common situations: Electron version upgrades breaking the prebuilt native module (NODE_MODULE_VERSION mismatch); running from a Windows Service/session 0 where user proxy settings are inaccessible; antivirus blocking sysproxy.exe; the bundled sysproxy.exe missing from the packaged app.
Related errors
- 没有找到占用该端口的进程
- 未找到处于 LISTENING 状态的进程
- 终止占用端口 ${port} 的进程失败。 PowerShell 方案: ${psError.message} CMD
- 证书路径为空,无法安装根证书。请确认证书文件已生成。
- 证书文件不存在: ${certPath}
AI-assisted analysis of docmirror/dev-sidecar@7710cd56cc (2026-08-31).
Data as JSON: /api/errors/4fd2f66826c3e006.
Report an issue: GitHub.