昨天的electron安裝氣死爸爸了,寫個隨筆發泄一下,
先明確自己的目地:在本機上跑一個electron-quick-start專案,
step1.下載專案到本地
新建一個目錄,在目錄下用git下載electron-quick-start專案檔案,
git clone http://www.github.com/electron/electron-quick-start
你要是這步下載不下來,說明你人品差
step2.安裝electron
方法1:全域安裝
npm install electron -g
這步說明你安裝electron到你的全域環境中,可是大部分人會卡在這里,

是因為electron install時候對應平臺的可執行檔案沒有下載成功,錯誤提示如下:
(node:1236) UnhandledPromiseRejectionWarning: Error: EPERM: operation not permitted, lstat 'C:\Users\ADMINI~1\AppData\Local\Temp\electron-download-2cy5xa\electron-v8.0.0-win32-x64.zip'
(node:1236) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1236) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
+ [email protected]
removed 3 packages and updated 1 package in 9.517s
官方解決的方法是

也就是在~/npmrc檔案中加入一段:
ELECTRON_MIRROR="https://cdn.npm.taobao.org/dist/electron/"
或者是直接在cmd中輸入:
npm config set ELECTRON_MIRROR=https://cdn.npm.taobao.org/dist/electron/
再執行
npm install electron -g
如果提示

表明安裝成功
下面測驗一下electron是否安裝成功,cmd中直接輸入electron,electron運行起來表明安裝成功,

前面的安裝可以在任意目錄下完成,如果是要運行electron-quick-start專案,需要你cd到該目錄下,執行npm start命令,

彈出electron-quikc-start專案,表示運行成功

方法2:在專案中安裝
前一個辦法是用全域中的electron運行專案,如果你想把electron下載到專案檔案夾中,并用專案檔案夾中的electron運行quick-start專案,可以cd到專案中,執行:
npm install
然后再
npm start

這個時候的electron版本就是專案指定的版本了,
注意:
改變mirror變數后你如果還是遇到這個問題:

可以通過cnpm 的方式安裝,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/181846.html
標籤:其他
