Electron安裝失敗


問題描述

自己通過npmyarn命令安裝electron時一直報錯無法安裝成功,將安裝源切換成淘寶源也是一樣的,一直報RequestError: unable to verify the first certificate的錯誤。

因為之前也出現過這個問題,是【HTTPS 證書驗證失敗】導致的,但是這次自己已經配置好HTTPS證書(這個問題的解決見 這里 )了,還是無法安裝成功。

> yarn add electron --dev
yarn add v1.22.10
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.  
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
[1/3] ⠄ electron-prebuilt
[3/3] ⠄ electron
error D:\Code\Web\StudyOrTest\electronInAction\create_env\node_modules\electron: Command failed.
Command: node install.js
Arguments:
Directory: D:\Code\Web\StudyOrTest\electronInAction\create_env\node_modules\electron
Output:
RequestError: unable to verify the first certificate
    at ClientRequest.<anonymous> (D:\Code\Web\StudyOrTest\electronInAction\create_env\node_modules\got\source\request-as-event-emitter.js:178:14)
    at Object.onceWrapper (events.js:422:26)
    at ClientRequest.emit (events.js:327:22)
    at ClientRequest.origin.emit (D:\Code\Web\StudyOrTest\electronInAction\create_env\node_modules\@szmarczak\http-timer\source\index.js:37:11)
    at TLSSocket.socketErrorListener (_http_client.js:426:9)
    at TLSSocket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)

問題原因

在網上找了一圈都沒有找到怎么解決的,然后在網上看到了 electron 7.0.0安裝失敗 網友說7.0.0開始安裝會請求Github源,導致安裝錯誤。但是他報的錯誤和我的錯誤是不一樣的,而且我也嘗試了一下訪問Github和直接訪問Electron的官方下載鏈接 發現能下載。

雖然上面沒有幫我解決問題,但是評論中有一句話讓我想到了問題的原因。

會不會這次也是官方更新導致的,因為我在10月份的時候還安裝過Electron,當時還能夠安裝,沒有任何問題,這次安裝就一直報這個錯誤,無法安裝。

於是我就去官方版本發布記錄(網址在 這里 ),我當時最新的版本是11.1.1,我一路嘗試安裝,發現10.1.5版本能夠安裝,到10.1.6之后就會報上面的錯誤。

至此,總算是找到了問題的原因,就是官方版本更新的問題(猜測還是和HTTPS 證書驗證有關),從10.1.5之后就無法安裝了。

解決方案

找到了原因那么就好解決了,指定安裝10.1.5版本就可以了,安裝命令如下:

// yarn安裝命令
> yarn add electron@10.1.5 --dev

// npm安裝命令
 > npm install electron@10.1.5 --save-dev

參考資料

  1. electron 7.0.0安裝失敗


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM