electron 遇到的问题汇总
一年前搞过 electron 当时感觉 electron 是基于浏览器内核的,很多操作收到浏览器策略的限制,很多想做的事没法实现。 后来又研究了 QT, QT 真的很帅,视图和业务逻辑的绑定逻辑,以及多进程的事件信号回调机制真的让我学到了很多。真的要说缺点的话,可能就是自己写的少, 然后比如写一个界面有种写原生 html 的感觉, 不像 web 有很多 ui 组件库和 style 可以用。
后来通过和别人的交流,发现 electron 可以直接调用 python 脚本。
一. 安装失败的问题
安装失败通常是下载失败,网上解决问题的方法还是挺多的,这里归纳一下我解决问题时候的思路:
- 通过 yarn 安装的话, 就算失败了也有 node_modules 文件夹,npm 则没有。
- 查看 node_modules/electron 下的 install.js, 很容易就会发现是通过 ‘@electron/get’ 下载的资源包。
- 可以直接查看 ‘@electron/get’ 的 readme.md,我通过查看 readme.md 发现了问题所在。
我安装失败是因为 npm 的 config 里面 electorn 的配置项小写了, 应该是大写。 下面是
#### Using environment variables for mirror options
Mirror options can also be specified via the following environment variables:
* `ELECTRON_CUSTOM_DIR` - Specifies the custom directory to download from.
* `ELECTRON_CUSTOM_FILENAME` - Specifies the custom file name to download.
* `ELECTRON_MIRROR` - Specifies the URL of the server to download from if the version is not a nightly version.
* `ELECTRON_NIGHTLY_MIRROR` - Specifies the URL of the server to download from if the version is a nightly version.
我的 npm 配置
registry=http://mirrors.cloud.tencent.com/npm/
ELECTRON_MIRROR=https://mirrors.cloud.tencent.com/npm/electron
ELECTRON_CUSTOM_DIR=25.8.0
直接敲 npm 回车, 可以看到 npm 配置文件的位置, 不用怀疑,直接复制粘贴就好了。
Specify configs in the ini-formatted file:
C:\Users\bboyx\.npmrc
本作品采用《CC 协议》,转载必须注明作者和本文链接