问题描述
我已遵循此网页上的建议
https://bitfrit.com/how-to-use-sqlite-with-electron/
但是当我重新加载页面以刷新窗口时,我仍然遇到问题。当我第一次启动页面时,运行npm start一切正常。刷新/重新加载页面时,出现以下错误
Fatal error: Error::Error napi_create_reference
1: 00007FF6822A45C6 node::Buffer::New+45414
2: 00007FF6822A4789 node::Buffer::New+45865
3: 00007FF6822A45F9 node::Buffer::New+45465
4: 00007FF683108F15 napi_fatal_error+149
5: 00007FFA0E941F3C
6: 00007FFA0E941CF7
7: 00007FFA0E955D3B
8: 00007FF68310AC26 napi_ref_threadsafe_function+1254
9: 00007FF6831262FC uv_translate_sys_error+2380
10: 00007FF6822C4163 uv_run+307
11: 00007FF68228D0D7 node::EmitAsyncDestroy+85607
12: 00007FF68228D4B6 node::EmitAsyncDestroy+86598
13: 00007FF68227695D node::FreeEnvironment+13
14: 00007FF67F6159D8 v8::OutputStream::WriteHeapStatsChunk+130520
15: 00007FF682179A65 IsSandBoxedProcess+2179013
16: 00007FF68398219F uv_fs_poll_getpath+8729887
17: 00007FF682C908B3 GetHandLeverifier+9953331
18: 00007FF682D15071 GetHandLeverifier+10495985
19: 00007FF682C7C236 GetHandLeverifier+9869750
20: 00007FF682D93494 GetHandLeverifier+11013140
21: 00007FF682D92F05 GetHandLeverifier+11011717
22: 00007FF682D1D1CE GetHandLeverifier+10529102
23: 00007FF682D1F908 GetHandLeverifier+10539144
24: 00007FF6820285CE IsSandBoxedProcess+797486
25: 00007FF68216B4E4 IsSandBoxedProcess+2120260
26: 00007FF6821840DC IsSandBoxedProcess+2221628
27: 00007FF682183F32 IsSandBoxedProcess+2221202
28: 00007FF68216AA04 IsSandBoxedProcess+2117476
29: 00007FF682F40725 GetHandLeverifier+12770981
30: 00007FF67FF99BD1 std::__1::vector<v8::cpuProfileDeoptFrame,std::__1::allocator<v8::cpuProfileDeoptFrame> >::vector<v8::cpuProfileDeoptFrame,std::__1::allocator<v8::cpuProfileDeoptFrame> >+1643473
31: 00007FF682F40CDA GetHandLeverifier+12772442
32: 00007FF681BB499A uv_cond_signal+1217946
33: 00007FF6823FAD74 GetHandLeverifier+951540
34: 00007FF6823F9061 GetHandLeverifier+944097
35: 00007FF681A5BCBC uv_mutex_unlock+2521420
36: 00007FF68230BCE4 uv_gettimeofday+278804
37: 00007FF68230B9C8 uv_gettimeofday+278008
38: 00007FF6822FC23B uv_gettimeofday+214635
39: 00007FF68230C2DE uv_gettimeofday+280334
40: 00007FF681A45B6C uv_mutex_unlock+2430972
41: 00007FF68218B994 IsSandBoxedProcess+2252532
42: 00007FF680E382E1 v8_inspector::V8StackTraceId::ToString+5677153
43: 00007FF681FCBB0B IsSandBoxedProcess+417899
44: 00007FF6800CCDEE v8::cpuProfilingOptions::max_samples+784398
45: 00007FF67F4A149F Ordinal0+5279
46: 00007FF68553EE12 uv_random+16903298
47: 00007FFA2FCD7034 BaseThreadInitThunk+20
48: 00007FFA310FCEC1 RtlUserThreadStart+33
当前我有以下index.js
index.js
const electron = require("electron");
const app = electron.app;
const browserWindow = electron.browserWindow;
let mainWindow;
var MysqL = require('MysqL');
const url = require('url');
const path = require('path');
app.on('ready',function() {
mainWindow = new browserWindow({
width: 1200,height: 800,'minWidth': 480,title:"DVD Library",webPreferences: {nodeIntegration: true}
})
mainWindow.on('closed',function() {
mainWindow = null;
});
mainWindow.loadURL(url.format({
pathname: path.join(__dirname,"index.html"),protocol: 'file:',slashes: true
}));
mainWindow.toggleDevTools();
});
index.html
<!DOCTYPE html>
<html>
<head>
<Meta charset="UTF-8">
<title>Hello World!</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script>let $ = require('./node_modules/jquery');</script>
<script>require('./node_modules/popper.js');</script>
<script>require('./node_modules/bootstrap');</script>
</head>
<body>
<form>
<div id="dvdlist" class="container">
</div>
</form>
</body>
<script>
const electron = require("electron");
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('dvds.db');
var dbrows;
Getsql();
function Getsql()
{
db.all("SELECT * FROM DVDS",(err,rows) => {
if (err){
}
PaintData(rows);
db.close();
});
}
function PaintData(rows)
{
var str = "<div class='table-responsive'>";
str += "<table class='table table-sm table-striped'>";
str += "<tr>";
str += "<th>Title</th>";
str += "<th>Category</th>";
str += "<th>Catalog ID</th>";
str += "</tr>";
for(var i in rows){
str += "<tr>";
str += "<td>"+rows[i].Title+"</td>";
str += "<td>"+rows[i].Category+"</td>";
str += "<td>"+rows[i].CatalogID+"</td>";
str += "</tr>";
}
str += "</table></div>";
$("#dvdlist").html(str)
}
</script>
</html>
package.json
{
"name": "dvds","version": "1.0.0","description": "DVD library","main": "index.js","scripts": {
"start": "electron .","package-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=assets/icons/mac/icon.icns --prune=true --out=release-builds","package-win": "electron-packager . electron-tutorial-app --overwrite --asar=true --platform=win32 --arch=ia32 --icon=assets/icons/win/icon.ico --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=\"AutoHARP 3\"","package-linux": "electron-packager . electron-tutorial-app --overwrite --asar=true --platform=linux --arch=x64 --icon=assets/icons/png/icon.png --prune=true --out=release-builds","postinstall": "install-app-deps"
},"author": "Fr David Klecker","license": "ISC","dependencies": {
"bootstrap": "^4.5.3","electron": "^10.1.4","jquery": "^3.5.1","MysqL": "^2.18.1","popper.js": "^1.16.1","sqlite3": "^5.0.0"
},"devDependencies": {
"electron-builder": "^22.9.1","electron-rebuild": "^2.2.0"
}
}
解决方法
尝试添加:
app.allowRendererProcessReuse = false;
之前:
app.on('ready',function() {
或者使用8或更早版本的电子版也可以。有关更多信息,请查看:https://github.com/electron/electron/issues/18397
我在这里偶然发现了此解决方案:https://github.com/electron/electron/issues/24933