昨天的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 的方式安装。