首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么Nodejs usb模块与电子相冲突?

为什么Nodejs usb模块与电子相冲突?
EN

Stack Overflow用户
提问于 2021-01-01 11:09:22
回答 1查看 502关注 0票数 1

很抱歉这么长的帖子,我一直在谷歌上搜索很多解决方案,但是找不到。我试图编写一个简单的电子应用程序来显示html页面(谢天谢地,这没有问题),并控制打印机,这件事必须通过通过npm安装的usb模块完成。这个模块和依赖于它的代码在纯node.js软件中总是完美地工作,所以这不是寻找问题的地方,但是我很难将它集成到我的电子应用程序中。我必须使用Ubuntu14.04,系统已经有节点12.20.0 +NPM6.14.8,这两个节点都是通过nvm安装的,没有任何警告(如果有任何已知的冲突,我可以安装不同的版本)。由于使用通过npm安装的电子的一系列困难,我求助于使用它的预构建的二进制包(版本11.1.1,但如果需要的话也可以更改),可以从https://github.com/electron/electron/releases/tag/v11.1.1下载。

我要做的是:

there

  • install

  • 解压缩软件包

  • ,转到文件夹/resources/app,并将我的源代码+默认package.json usb模块1.6.3:$npm安装usb --save-dev

  • go返回主dir,并运行应用程序:$./e-

我得到的是:

代码语言:javascript
复制
./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

好的,这是可以理解的,因为usb是一个本机模块,必须重新构建。folder/resources/app

  • $npm

  • 返回到安装电子重建--dev
  • ,如果需要的话,会得到大量的输出,但最后都找到了发现的0漏洞,所以我认为它是ok
  • $./node_modules/.bin/electron-rebuild

代码语言:javascript
复制
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

11.1.1

  • rebuild

  • 不知道为什么,但它很容易解决:$../node_node/..bin/电子-重构-版本的完成:美妙,让我们回到主directory
  • try运行应用程序:$./

代码语言:javascript
复制
./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)

发生什么事了呢?就像电子重建什么都没做。我可以改变一切,除了操作系统和(除非没有其他解决方案可用),我使用电子预建包,而不是在$npm安装电子。你知道怎么回事吗?谢谢大家的关注。

EN

回答 1

Stack Overflow用户

发布于 2021-01-01 14:55:26

你必须重建任何

代码语言:javascript
复制
npm rebuild
# or
npm install electron-rebuild --save-dev
./node_modules/.bin/electron-rebuild
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65529165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档