一次性解决electron-builder依赖无法安装的问题

152 阅读1分钟

我开发Electron项目(Windows环境)时,需要在不同设备开发,执行 yarn install 安装依赖时经常会碰到:

Arguments: ls-remote --tags --heads https://github.com/electron/node-gyp.git
Directory: C:\xxxxx
Output:
fatal: unable to access 'https://hub.njuu.cf/electron/node-gyp.git/': TLS connect error: error:00000000:lib(0)::reason(0)

这个 node-gyp 其实是 electron-builder 引用的第三方依赖。

豆包、ChatGPT、文心一言与Deepseek都走了圈,无法解决,因为这是个必要包,所以必须安装。原本想保持所有依赖都通过 yarn 来安装,最终无奈妥协。妥协方案:

使用cnpm单独安装

方法:

npm install -g cnpm --registry=https://registry.npmmirror.com
cnpm install -D electron

最终成功:

image.png