electron打包ffi-napi报错 npm ERR! gyp reason: read ECONNRESET

本文介绍了一个关于electron+vue项目中使用ffi-napi依赖包时遇到的打包错误问题及解决方法。错误主要表现为网络连接失败导致的fetch error,通过更换网络连接方式成功解决了该问题。

问题描述

这个问题用了我两天的时间,所以记录一下。

我们项目是使用electron+vue,做支付功能的时候需要使用到ffi-napi依赖包。
最后打包的时候ffi-napi报错了,在package.json中去掉ffi-napi就可以打包,但是打包运行后提示缺少ffi-napi,所以必须带着ffi-napi打包。

打包的时候报下面的错误
在这里插入图片描述

 OKAY  take it away `electron-builder`

  • electron-builder version=20.44.4
  • loaded configuration file=package.json ("build" field)
  • writing effective config file=build\builder-effective-config.yaml
  • rebuilding native production dependencies platform=win32 arch=ia32
Error: C:\Program Files (x86)\nodejs\node.exe exited with code 1
Error output:
npm ERR! code 1
npm ERR! path D:\Project\zyd-windows\node_modules\ffi-napi
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node-gyp-build
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@8.4.1
npm ERR! gyp info using node@14.17.0 | win32 | ia32
npm ERR! gyp info find Python using Python version 3.8.5 found at "C:\Users\yaoqi\AppData\Local\Programs\Python\Python38\python.exe"
npm ERR! gyp http GET https://atom.io/download/electron/v9.4.4/node-v9.4.4-headers.tar.gz
npm ERR! gyp WARN install got an error, rolling back install
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack FetchError: request to https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist/v9.4.4/node-v9.4.4-headers.tar.gz failed, reason: read ECONNRESET
npm ERR! gyp ERR! stack     at ClientRequest.<anonymous> (D:\Project\zyd-windows\node_modules\minipass-fetch\lib\index.js:110:14)
npm ERR! gyp ERR! stack     at ClientRequest.emit (events.js:376:20)
npm ERR! gyp ERR! stack     at TLSSocket.socketErrorListener (_http_client.js:475:9)
npm ERR! gyp ERR! stack     at TLSSocket.emit (events.js:388:22)
npm ERR! gyp ERR! stack     at emitErrorNT (internal/streams/destroy.js:106:8)
npm ERR! gyp ERR! stack     at emitErrorCloseNT (internal/streams/destroy.js:74:3)
npm ERR! gyp ERR! stack     at processTicksAndRejections (internal/process/task_queues.js:82:21)
npm ERR! gyp ERR! System Windows_NT 10.0.22000
npm ERR! gyp ERR! command "C:\\Program Files (x86)\\nodejs\\node.exe" "D:\\Project\\zyd-windows\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd D:\Project\zyd-windows\node_modules\ffi-napi
npm ERR! gyp ERR! node -v v14.17.0
npm ERR! gyp ERR! node-gyp -v v8.4.1
npm ERR! gyp ERR! not ok

核心问题

上面的错误主要是
npm ERR! gyp ERR! stack FetchError: request to https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist/v9.4.4/node-v9.4.4-headers.tar.gz failed, reason: read ECONNRESET

解决过程

刚开始我以为是ffi-napi依赖包的问题,然后重新npm install了好多次,打包依然是这个问题。
然后百度有人说是镜像源的问题,换了镜像源还是不行。

最后仔细看了报错里面最后原因是read ECONNRESET,网上其他人报错都是403,我的是根本没连接上服务器。然后我就怀疑是网络的问题。因为我连的是公司的网络,公司的网络经常会屏蔽一些东西,比如哔哩哔哩就打不开。

解决方法

我本来连的是公司的wifi,更换了一下网络,打开手机热点,让电脑连接手机热点。
然后就打包成功了!
在这里插入图片描述

npm ERR! code 1 npm ERR! path D:\dpproject\dpkj\dpkj-kxd\node_modules\ffi-napi npm ERR! command failed npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node-gyp-build npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using node-gyp@8.4.1 npm ERR! gyp info using node@18.19.1 | win32 | x64 npm ERR! gyp info find Python using Python version 3.9.7 found at "E:\anaconda\python.exe" npm ERR! gyp ERR! find VS npm ERR! gyp ERR! find VS msvs_version not set from command line or npm config npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt npm ERR! gyp ERR! find VS checking VS2022 (17.4.33213.308) found at: npm ERR! gyp ERR! find VS "E:\Visual Studio\2022\Community" npm ERR! gyp ERR! find VS - found "Visual Studio C++ core features" npm ERR! gyp ERR! find VS - found VC++ toolset: v143 npm ERR! gyp ERR! find VS - missing any Windows SDK npm ERR! gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use npm ERR! gyp ERR! find VS looking for Visual Studio 2015 npm ERR! gyp ERR! find VS - not found npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8 npm ERR! gyp ERR! find VS npm ERR! gyp ERR! find VS ************************************************************** npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload. npm ERR! gyp ERR! find VS For more information consult the documentation at: npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows npm ERR! gyp ERR! find VS ************************************************************** npm ERR! gyp ERR! find VS npm ERR! gyp ERR! configure error npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use npm ERR! gyp ERR! stack at VisualStudioFinder.fail (D:\dpproject\dpkj\dpkj-kxd\node_modules\node-gyp\lib\find-visualstudio.js:122:47) npm ERR! gyp ERR! stack
最新发布
09-03
评论 6
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值