昨天的electron安裝氣死爸爸了,寫個隨筆發泄一下。node
先明確本身的目地:在本機上跑一個electron-quick-start項目。git
新建一個目錄,在目錄下用git下載electron-quick-start項目文件。github
git clone http://www.github.com/electron/electron-quick-start
你要是這步下載不下來,說明你人品差shell
npm install electron -g
這步說明你安裝electron到你的全局環境中。但是大部分人會卡在這裏。npm
是由於electron install時候對應平臺的可執行文件沒有下載成功,錯誤提示以下:vim
(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. + electron@8.0.0 removed 3 packages and updated 1 package in 9.517s
官方解決的方法是
promise
也就是在~/npmrc文件中加入一段:electron
ELECTRON_MIRROR="https://cdn.npm.taobao.org/dist/electron/"
或者是直接在cmd中輸入:async
npm config set ELECTRON_MIRROR=https://cdn.npm.taobao.org/dist/electron/
再執行ide
npm install electron -g
若是提示
代表安裝成功
下面測試一下electron是否安裝成功。cmd中直接輸入electron,electron運行起來代表安裝成功。
前面的安裝能夠在任意目錄下完成,若是是要運行electron-quick-start項目,須要你cd到該目錄下,執行npm start命令。
彈出electron-quikc-start項目,表示運行成功
前一個辦法是用全局中的electron運行項目。若是你想把electron下載到項目文件夾中,並用項目文件夾中的electron運行quick-start項目,能夠cd到項目中,執行:
npm install
而後再
npm start
這個時候的electron版本就是項目指定的版本了。
能夠經過cnpm 的方式安裝。