electron問題整理

打包配置問題

 electron-packager . HelloWorld --platform=win32 --arch=x64 --out=./build --app-version=0.0.1

注意參數 --asar:asar打包可以隱藏代碼邏輯,減少文件數量,但是asar也帶來了第三方資源加載失敗的問題

引用ffi調用dll文件時遇到的問題

在這裏插入圖片描述
報錯NODE_MODULE_VERSION版本不對

由於chrome內核不同,需要編譯成一致的,才能讓node程序運行在Electron上,

所以使用node-gyp重新編譯指定一下abi值爲對應版本

node-gyp rebuild --target=5.0.8 --arch=x64 --abi=70 --dist-url=https://npm.taobao.org/mirrors/atom-shell
(使用這個命令編譯發現新錯誤)
在這裏插入圖片描述
高版本的electron,比如4.0和5.0以上的版本rebuild報錯,
2.0,3.0版本能夠成功rebuild

最後在ffi的GitHub官網上找到issues,有大佬提交了解決方案(https://github.com/node-ffi/node-ffi/issues/557)

“dependencies”: {
“ffi”: “github:lxe/node-ffi#node-12”,
“ref”: “github:lxe/ref#node-12”,
“ref-struct”: “github:lxe/ref-struct#node-12”,
}
在這裏插入圖片描述
報錯Win32 error 193

node是64位,而dll文件是32位,報錯

在這裏插入圖片描述
electron 5.0 版本,原來能運行的代碼報錯提示require is not defined,

經查相關資料,原來官方在5.0版本修改了nodeIntegration的默認值,官方說明如下:
The default values of nodeIntegration and webviewTag are now false to improve security.

解決辦法:修改創建BrowserWindow部分的相關代碼,設置屬性webPreferences.nodeIntegration爲 true,
let win = new BrowserWindow({
webPreferences: {
nodeIntegration: true
}
})

在這裏插入圖片描述

未知錯誤,調取dll方法使DevTools奔潰,有說是chrome內部錯誤,使用高版本electron可以解決(自測沒有效果)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章