electron 安装失败解决办法

5,651 阅读1分钟

npm i electron -D安装失败,报错:

$ npm i electron -D
...
> electron@7.1.4 postinstall D:\projects\logmei-electron\demo\node_modules\electron
> node install.js

(node:17704) UnhandledPromiseRejectionWarning: RequestError: read ECONNRESET
    at ClientRequest.<anonymous> (D:\projects\logmei-electron\demo\node_modules\got\source\request-as-event-emitter.js:178:14)s-event-emitter.js:178:14)
    at Object.onceWrapper (events.js:291:20)
    at ClientRequest.emit (events.js:208:15)                                                        r\source\index.js:37:11)
    at ClientRequest.origin.emit (D:\projects\logmei-electron\demo\node_modules\@szmarczak\http-timer\source\index.js:37:11)r\source\index.js:37:11)
    at TLSSocket.socketErrorListener (_http_client.js:399:9)
    at TLSSocket.emit (events.js:203:13)
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at processTicksAndRejections (internal/process/task_queues.js:77:11)
(node:17704) 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:17704) [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.


解决方法:

  • 安装 cross-env

给后面的命令设置环境变量(设置proccess.env)

  • 更新下,新版本已经是 7.0.1 了, 如果你用的是 7.0.1, 注意修改为cross-env npm_config_electron_mirror="npm.taobao.org/mirrors/ele…" npm_config_electron_custom_dir="7.0.1" npm install, 也就是 npm_config_electron_custom_dir要设置为版本号`**
#Install cross-env, 注意是全局安装
npm install -g cross-env
#Clone this repository
git clone https://github.com/electron/electron-quick-start
# Go into the repository
cd electron-quick-start
# Install dependencies
cross-env npm_config_electron_mirror="https://npm.taobao.org/mirrors/electron/" npm_config_electron_custom_dir="7.0.0" npm install

原文章地址