gpt4 book ai didi

javascript - Electron/USB不兼容的版本

转载 作者:行者123 更新时间:2023-12-03 12:42:11 25 4
gpt4 key购买 nike

我发现了多个与此类似的问题,但似乎没有一个解决方案对我有用。我正在尝试使用 USB 库 (https://www.npmjs.com/package/usb) 来访问 USB 设备,只要它是没有 Electron 的命令行测试应用程序,它就可以完美运行。我在 Ubuntu 14 计算机上安装了 Electron 我正在使用 npm install electron --save-dev 并且他们网站提供的测试应用程序也可以工作,但是当我添加我的 usbtools.js 模块时

const usb = require('usb');
//...
//Example function
exports.writeBytes = function writeBytes(deviceObj, dataOut, onWriteOk) {
deviceObj._epOut.transfer(dataOut, (err) => {});
};
//...

并从 html 页面(通过内联 javascript)调用其导出的函数,应用程序加载一个空白页面并且 DevTools 断开连接。当我用 F5 重新加载页面时,DevTools 控制台给我以下消息:
/home/carl/prstatjs_dist/node_modules/bindings/bindings.js:121 Uncaught Error: The module '/home/carl/prstatjs_dist/node_modules/usb/build/Release/usb_bindings.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 79. This version of Node.js requires
NODE_MODULE_VERSION 75. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
at process.func (electron/js2c/asar.js:140)
at process.func [as dlopen] (electron/js2c/asar.js:140)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:922)
at Object.func (electron/js2c/asar.js:140)
at Object.func [as .node] (electron/js2c/asar.js:140)
at Module.load (internal/modules/cjs/loader.js:735)
at Module._load (internal/modules/cjs/loader.js:648)
at Module._load (electron/js2c/asar.js:717)
at Function.Module._load (electron/js2c/asar.js:717)
at Module.require (internal/modules/cjs/loader.js:775)
func @ electron/js2c/asar.js:140
func @ electron/js2c/asar.js:140
Module._extensions..node @ internal/modules/cjs/loader.js:922
func @ electron/js2c/asar.js:140
func @ electron/js2c/asar.js:140
Module.load @ internal/modules/cjs/loader.js:735
Module._load @ internal/modules/cjs/loader.js:648
Module._load @ electron/js2c/asar.js:717
Module._load @ electron/js2c/asar.js:717
Module.require @ internal/modules/cjs/loader.js:775
require @ internal/modules/cjs/helpers.js:68
bindings @ /home/carl/prstatjs_dist/node_modules/bindings/bindings.js:112
(anonymous) @ /home/carl/prstatjs_dist/node_modules/usb/usb.js:1
(anonymous) @ /home/carl/prstatjs_dist/node_modules/usb/usb.js:526
Module._compile @ internal/modules/cjs/loader.js:880
Module._extensions..js @ internal/modules/cjs/loader.js:892
Module.load @ internal/modules/cjs/loader.js:735
Module._load @ internal/modules/cjs/loader.js:648
Module._load @ electron/js2c/asar.js:717
Module._load @ electron/js2c/asar.js:717
Module.require @ internal/modules/cjs/loader.js:775
require @ internal/modules/cjs/helpers.js:68
(anonymous) @ /home/carl/prstatjs_dist/prstat/usbtools.js:1
(anonymous) @ /home/carl/prstatjs_dist/prstat/usbtools.js:319
Module._compile @ internal/modules/cjs/loader.js:880
Module._extensions..js @ internal/modules/cjs/loader.js:892
Module.load @ internal/modules/cjs/loader.js:735
Module._load @ internal/modules/cjs/loader.js:648
Module._load @ electron/js2c/asar.js:717
Module._load @ electron/js2c/asar.js:717
Module.require @ internal/modules/cjs/loader.js:775
require @ internal/modules/cjs/helpers.js:68
(anonymous) @ /home/carl/prstatjs_dist/prstat/stampanti.js:3
(anonymous) @ /home/carl/prstatjs_dist/prstat/stampanti.js:354
Module._compile @ internal/modules/cjs/loader.js:880
Module._extensions..js @ internal/modules/cjs/loader.js:892
Module.load @ internal/modules/cjs/loader.js:735
Module._load @ internal/modules/cjs/loader.js:648
Module._load @ electron/js2c/asar.js:717
Module._load @ electron/js2c/asar.js:717
Module.require @ internal/modules/cjs/loader.js:775
require @ internal/modules/cjs/helpers.js:68
(anonymous) @ /home/carl/prstatjs_dist/prstat/prstat.js:2
(anonymous) @ /home/carl/prstatjs_dist/prstat/prstat.js:385
Module._compile @ internal/modules/cjs/loader.js:880
Module._extensions..js @ internal/modules/cjs/loader.js:892
Module.load @ internal/modules/cjs/loader.js:735
Module._load @ internal/modules/cjs/loader.js:648
Module._load @ electron/js2c/asar.js:717
Module._load @ electron/js2c/asar.js:717
Module.require @ internal/modules/cjs/loader.js:775
require @ internal/modules/cjs/helpers.js:68
(anonymous) @ esempio_electron_codice.js:3
Show 23 more frames

据我了解,这是因为 Electron 为其工作框架提供了基于 Chromium 的 Web 浏览器,而该浏览器又不支持当前的 node-usb 构建。我已经尝试按照建议进行重建。
有人遇到过这个问题吗?我需要使用 Electron,但我可以自由地使用另一个库来访问 USB 设备,只要它允许我进行低级别控制(例如:选择接口(interface)和端点,我不能只通过串行线发送数据)。

编辑 1:
Node 版本:13.5.0
npm 版本:6.13.4
usb 库版本:1.6.2(目前最新。npm 无法安装 1.6.0 之前的任何内容)
Electron 版:7.1.7

最佳答案

幸运的是,我找到了解决方案:

$npm install electron-rebuild --dev
$./node_modules/.bin/electron-rebuild

与常规重建不同,这似乎有效。

关于javascript - Electron/USB不兼容的版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59579945/

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