vue 安裝electron-builder報錯


通過命令 vue add electron-builder 安裝 electron-builder 報如下錯誤:

D:\Code\Web\StudyOrTest\vue_init> vue add electron-builder
 WARN  There are uncommitted changes in the current repository, it's recommended to commit or stash them first.
? Still proceed? Yes

�  Installing vue-cli-plugin-electron-builder...

yarn add v1.22.10
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@2.1.3: The platform "win32" is incompatible with this module.
info "fsevents@2.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.13: The platform "win32" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
[4/4] ⠠ electron
[-/4] ⠠ waiting...
[3/4] ⠠ yorkie
error D:\Code\Web\StudyOrTest\vue_init\node_modules\electron: Command failed.
Exit code: 1
Command: node install.js
Arguments:
Directory: D:\Code\Web\StudyOrTest\vue_init\node_modules\electron
Output:
RequestError: unable to verify the first certificate
    at ClientRequest.<anonymous> (D:\Code\Web\StudyOrTest\vue_init\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\vue_init\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)



 ERROR  command failed: yarn add vue-cli-plugin-electron-builder -D --tilde
  • 錯誤原因

自己在網上找了一圈,都沒有找到為什么錯了,看到 unable to verify the first certificate 錯誤提示的時候,我還以為和之前yarn安裝包報錯是同一個問題(問題參見 yarn安裝包時報 unable to verify the first certificate 錯誤 ),但是自己一看設置沒有問題。

之后我將問題聚焦到了錯誤提示的第 19 到 23 行,即如下內容:

error D:\Code\Web\StudyOrTest\vue_init\node_modules\electron: Command failed.
Exit code: 1
Command: node install.js
Arguments:
Directory: D:\Code\Web\StudyOrTest\vue_init\node_modules\electron

自己在網上搜索了一下,發現這個好像是安裝 electron 的信息,所以猜測可能是安裝 electron 這一步出了問題。

下一步我用 yarn add electron --dev 命令單獨安裝 electron ,果然報了同樣的錯誤。但是自己之前也是通過同樣的步驟去安裝 electron 時並沒有這個錯誤,中間自己做過的操作就是為了提升包的下載速度將下載源從官方源切換到了淘寶源。

自己驗證了一下猜想,將安裝源切換回官方源(由於我是用yarn安裝的,所以需要將yarn和npm的安裝源都切換回官方源), electron 立馬就安裝成功了。

原因: 通過淘寶源安裝 electron-builder 導致的。

  • 解決方案

找到原因了,也就好解決了,通過如下命令將yarn和npm的安裝源切換回官方源即可。

yarn config set registry https://registry.yarnpkg.com		// vue初始化時,選擇的時npm的不需要這一步
npm config set registry https://registry.npmjs.org


免責聲明!

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



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