简体   繁体   English

为什么 Nodejs usb 模块与 Electron 冲突?

[英]Why is Nodejs usb module conflicting with Electron?

sorry for the long post, I've been googling a lot for a solution but couldn't find one.很抱歉这篇长文,我一直在谷歌上搜索一个解决方案,但找不到一个。 I'm trying to write a simple Electron app to display an html page (no problem with that thankfully) and to control a printer, thing that must be done through the usb module installed via npm. I'm trying to write a simple Electron app to display an html page (no problem with that thankfully) and to control a printer, thing that must be done through the usb module installed via npm. That module and the code that relies on it always worked perfectly in pure node.js software so that's not where to look for the problem, but I'm having a hard time integrating it in my Electron app.该模块和依赖它的代码总是在纯 node.js 软件中完美运行,所以这不是寻找问题的地方,但我很难将它集成到我的 Electron 应用程序中。 I have to use Ubuntu 14.04 , and the system already has node 12.20.0 + npm 6.14.8 , both installed via nvm without any warning (I can install different versions if there's any known conflict).我必须使用Ubuntu 14.04 ,并且系统已经有节点 12.20.0 + npm 6.14.8 ,都通过 nvm 安装而没有任何警告(如果有任何已知的冲突,我可以安装不同的版本)。 Due to a series of difficulties using Electron installed via npm, I resorted to using the prebuilt binaries package of it ( version 11.1.1 , but again that's something I can change if needed) that can be downloaded from https://github.com/electron/electron/releases/tag/v11.1.1 Due to a series of difficulties using Electron installed via npm, I resorted to using the prebuilt binaries package of it ( version 11.1.1 , but again that's something I can change if needed) that can be downloaded from https://github.com /electron/electron/releases/tag/v11.1.1

Here's what I do:这就是我所做的:

  • unzip the package解压 package
  • go to [folder]/resources/app and put my source code + default package.json there go 到 [文件夹]/resources/app 并将我的源代码 + 默认 package.json 放在那里
  • install usb module 1.6.3: $npm install usb --save-dev安装 usb 模块 1.6.3: $npm install usb --save-dev
  • go back to the main dir and run the app: $./electron go 回到主目录并运行应用程序: $./electron

This is what I get:这就是我得到的:

./electron: /usr/lib/x86_64-linux-gnu/libxkbcommon.so.0: no version information available (required by ./electron)
/home/totem/totem/electron: /usr/lib/x86_64-linux-gnu/libxkbcommon.so.0: no version information available (required by /home/totem/totem/electron)
/home/totem/totem/electron: /usr/lib/x86_64-linux-gnu/libxkbcommon.so.0: no version information available (required by /home/totem/totem/electron)
Fontconfig warning: "/etc/fonts/fonts.conf", line 86: unknown element "blank"
A JavaScript error occurred in the main process
Uncaught Exception:
Error: The module '/home/totem/totem/resources/app/node_modules/usb/build/Release/usb_bindings.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 85. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at process.func [as dlopen] (electron/js2c/asar_bundle.js:5:1812)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1203:18)
    at Object.func [as .node] (electron/js2c/asar_bundle.js:5:1812)
    at Module.load (internal/modules/cjs/loader.js:992:32)
    at Module._load (internal/modules/cjs/loader.js:885:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12738)
    at Module.require (internal/modules/cjs/loader.js:1032:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at bindings (/home/totem/totem/resources/app/node_modules/bindings/bindings.js:112:48)
    at Object.<anonymous> (/home/totem/totem/resources/app/node_modules/usb/usb.js:1:57)
Segmentation fault
  • Ok, that's understandable because usb is a native module and has to be rebuilt.好的,这是可以理解的,因为 usb 是原生模块,必须重新构建。
  • go back to [folder]/resources/app go 返回[文件夹]/resources/app
  • $npm install electron-rebuild --dev $npm 安装电子重建 --dev
  • get a LOT of output that I will provide if requested, but it all ends with found 0 vulnerabilities so I assume it's ok如果需要,我会提供很多 output,但一切都以发现 0 个漏洞而告终,所以我认为没问题
  • $./node_modules/.bin/electron-rebuild $./node_modules/.bin/electron-rebuild
An unhandled error occurred inside electron-rebuild
Unable to find electron's version number, either install it or specify an explicit version

Error: Unable to find electron's version number, either install it or specify an explicit version
    at /home/totem/totem/resources/app/node_modules/electron-rebuild/lib/src/cli.js:82:19
  • not sure why, but it's easily solved: $./node_modules/.bin/electron-rebuild --version 11.1.1不知道为什么,但很容易解决: $./node_modules/.bin/electron-rebuild --version 11.1.1
  • rebuild complete : wonderful, let's go back to the main directory重建完成:太好了,让我们 go 回到主目录
  • try to run the app: $./electron尝试运行应用程序: $./electron
./electron: /usr/lib/x86_64-linux-gnu/libxkbcommon.so.0: no version information available (required by ./electron)
/home/totem/totem/electron: /usr/lib/x86_64-linux-gnu/libxkbcommon.so.0: no version information available (required by /home/totem/totem/electron)
/home/totem/totem/electron: /usr/lib/x86_64-linux-gnu/libxkbcommon.so.0: no version information available (required by /home/totem/totem/electron)
Fontconfig warning: "/etc/fonts/fonts.conf", line 86: unknown element "blank"
A JavaScript error occurred in the main process
Uncaught Exception:
Error: The module '/home/totem/totem/resources/app/node_modules/usb/build/Release/usb_bindings.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 85. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at process.func [as dlopen] (electron/js2c/asar_bundle.js:5:1812)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1203:18)
    at Object.func [as .node] (electron/js2c/asar_bundle.js:5:1812)
    at Module.load (internal/modules/cjs/loader.js:992:32)
    at Module._load (internal/modules/cjs/loader.js:885:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12738)
    at Module.require (internal/modules/cjs/loader.js:1032:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at bindings (/home/totem/totem/resources/app/node_modules/bindings/bindings.js:112:48)
    at Object.<anonymous> (/home/totem/totem/resources/app/node_modules/usb/usb.js:1:57)

What's happening?发生了什么? It's like electron-rebuild did nothing at all.就像电子重建根本没有做任何事情一样。 I can change everything but the operating system and (unless no other solution is available) the fact that i use Electron prebuilt packages instead on $npm install electron .我可以更改除操作系统之外的所有内容,并且(除非没有其他解决方案可用)我使用 Electron 预构建包而不是$npm install electron的事实。 Any idea what's wrong?知道有什么问题吗? Thank you all for your attention.谢谢大家的关注。

You must rebuild any你必须重建任何

npm rebuild
# or
npm install electron-rebuild --save-dev
./node_modules/.bin/electron-rebuild

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM