gpt4 book ai didi

node.js - 在 Electron 应用程序中使用 Dbus 包(构建过程)

转载 作者:行者123 更新时间:2023-12-03 12:27:19 31 4
gpt4 key购买 nike

当我需要 DBus 时,我遇到了这个问题来自 dbus包裹

const { app, BrowserWindow } = require("electron");
const DBus = require('dbus');

app.whenReady().then(() => {
var win = new BrowserWindow({ width: 600, height: 500 });
win.loadFile('index.html');

win.webContents.openDevTools();
});
所以当我执行这段代码时,我得到了这个错误:
> electron script.js

App threw an error during load
Error: Module did not self-register: '/home/bislem/projects/test/electron/node_modules/dbus/build/Release/dbus.node'.
at process.func [as dlopen] (electron/js2c/asar.js:140:31)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1196:18)
at Object.func [as .node] (electron/js2c/asar.js:140:31)
at Module.load (internal/modules/cjs/loader.js:981:32)
at Module._load (internal/modules/cjs/loader.js:881:14)
at Function.Module._load (electron/js2c/asar.js:769:28)
at Module.require (internal/modules/cjs/loader.js:1023:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/home/bislem/projects/test/electron/node_modules/dbus/lib/dbus.js:3:13)
at Module._compile (internal/modules/cjs/loader.js:1145:30)
A JavaScript error occurred in the main process
Uncaught Exception:
Error: Module did not self-register: '/home/bislem/projects/test/electron/node_modules/dbus/build/Release/dbus.node'.
at process.func [as dlopen] (electron/js2c/asar.js:140:31)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1196:18)
at Object.func [as .node] (electron/js2c/asar.js:140:31)
at Module.load (internal/modules/cjs/loader.js:981:32)
at Module._load (internal/modules/cjs/loader.js:881:14)
at Function.Module._load (electron/js2c/asar.js:769:28)
at Module.require (internal/modules/cjs/loader.js:1023:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/home/bislem/projects/test/electron/node_modules/dbus/lib/dbus.js:3:13)
at Module._compile (internal/modules/cjs/loader.js:1145:30)
我搜索了这个错误并尝试了一些解决方案,但没有一个有效( npm rebuildnpm update ,删除 node_modules 文件夹然后 npm install ,使用不同版本的 Node 使用 nvm 命令),但是当自己运行每个包,(运行 electron 使用启动脚本 electron . ,并运行 dbusnode script.js )它们正常工作。
安装 dbus 时出现此问题包裹 :
console when installing dbus , console when installing dbus part 2
我的 package.json 文件:
{
"name": "electrontest",
"version": "1.0.0",
"description": "",
"main": "script.js",
"scripts": {
"start": "electron script.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bootstrap": "^4.5.3",
"dbus": "^1.0.7",
"electron": "^10.1.5"
}
}
所以我的问题是构建/运行此类代码的正确方法是什么? ||如何并排使用这两个包?

最佳答案

你需要跑

npm install --save-dev electron-rebuild && npx electron-rebuild

更多关于在 Electron 中使用 native Node 模块 here

关于node.js - 在 Electron 应用程序中使用 Dbus 包(构建过程),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64789511/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com