上篇文章基本上能解決80%electron+node打包遇到的問題:https://www.cnblogs.com/mdorg/p/10417945.html,
大家能看到的基本上是版本號,但是abi到底是個什么玩意?怎么獲取成為一個問題。
這里提供一個abi與target轉換的小demo,僅供參照:
npm中有個node-abi的第三方庫,把這個引用到你的electron代碼中,如這樣:
const nodeAbi = require('node-abi');
在package.json中配置如下:

在渲染程序中的應用:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello Electron!</title>
</head>
<body>
<h3>
<select id="sel_val">
<option value="node" select='select'>node</option>
<option value="electron">electron</option>
</select>
<input type="text" id="txt_val">
<button type="button" onclick="getAbi()">GetABI</button>
<button type="button" onclick="getTarget()">GetTarget</button>
<div>
ABI:<span id="span_abi_val"></span>
TARGET:<span id="span_target_val"></span>
</div>
<div id="error" style="color:red"></div>
</h3>
<script>
const nodeAbi = require('node-abi');
const error = document.getElementById('error');
const sel = document.getElementById('sel_val');
const txt = document.getElementById("txt_val");
function getAbi(){
try{
error.innerHTML = "";
const val = nodeAbi.getAbi(txt.value, sel.value);
document.getElementById('span_abi_val').innerHTML = val;
}
catch(ex){
error.innerHTML = ex.message
}
}
function getTarget(){
try{
error.innerHTML = "";
const val = nodeAbi.getTarget(txt.value, sel.value)
document.getElementById('span_target_val').innerHTML = val;
}
catch(ex){
error.innerHTML = ex.message
}
}
</script>
</body>
</html>
具體效果如下:

如果你當前的使用的node版本是10.15.0,那么abi是多少呢?

那么electron中的abi為64的版本號是多少呢?

這樣在electron+node開發項目時,就可以選擇abi一致的版本,這樣可以避免不少問題。
此問題就先這樣,希望對你有所幫助!
