为 Electron 构建节点 USB

问题描述 投票:0回答:1

我从 GitHub 克隆了

electron-react-boilerplate
,它随 Electron 11.0.1 一起提供:

git clone --depth 1 --single-branch https://github.com/electron-react-boilerplate/electron-react-boilerplate.git test

接下来,我通过运行

yarn
安装模板的依赖项。一切都已安装,并且
yarn start
正确启动程序。

接下来,我尝试按照 Electron 文档中有关安装本机依赖项的说明,在

node-usb
文件夹中安装带有
yarn add usb
src
包。安装运行正常,之后
yarn electron-rebuild
会自动运行,执行模板的内置
ElectronRebuild.js
:

electron-rebuild --parallel --force --types prod,dev,optional --module-dir .

由于新安装的

node-usb
软件包而失败:

⠦ Building modules: 0/1gyp info find Python using Python version 3.6.9 found at "/usr/bin/python3"
⠧ Building modules: 0/1gyp http GET https://www.electronjs.org/headers/v11.0.1/node-v11.0.1-headers.tar.gz
⠋ Building modules: 0/1gyp http 200 https://www.electronjs.org/headers/v11.0.1/node-v11.0.1-headers.tar.gz
⠴ Building modules: 0/1gyp http GET https://www.electronjs.org/headers/v11.0.1/SHASUMS256.txt
⠧ Building modules: 0/1gyp http 200 https://www.electronjs.org/headers/v11.0.1/SHASUMS256.txt
gyp info spawn /usr/bin/python3
gyp info spawn args [
gyp info spawn args   '/home/user/Projects/test/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/home/user/Projects/test/src/node_modules/usb/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/home/user/Projects/test/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/home/user/Projects/test/src/node_modules/usb/11.0.1/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/home/user/Projects/test/src/node_modules/usb/11.0.1',
gyp info spawn args   '-Dnode_gyp_dir=/home/user/Projects/test/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/home/user/Projects/test/src/node_modules/usb/11.0.1/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/home/user/Projects/test/src/node_modules/usb',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
⠏ Building modules: 0/1gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
⠋ Building modules: 0/1make: Entering directory '/home/user/Projects/test/src/node_modules/usb/build'
  CC(target) Release/obj.target/libusb/libusb/libusb/core.o
⠦ Building modules: 0/1  CC(target) Release/obj.target/libusb/libusb/libusb/descriptor.o
⠇ Building modules: 0/1  CC(target) Release/obj.target/libusb/libusb/libusb/hotplug.o
⠋ Building modules: 0/1  CC(target) Release/obj.target/libusb/libusb/libusb/io.o
⠸ Building modules: 0/1  CC(target) Release/obj.target/libusb/libusb/libusb/strerror.o
  CC(target) Release/obj.target/libusb/libusb/libusb/sync.o
⠦ Building modules: 0/1  CC(target) Release/obj.target/libusb/libusb/libusb/os/poll_posix.o
⠧ Building modules: 0/1  CC(target) Release/obj.target/libusb/libusb/libusb/os/threads_posix.o
⠇ Building modules: 0/1  CC(target) Release/obj.target/libusb/libusb/libusb/os/linux_usbfs.o
⠴ Building modules: 0/1  CC(target) Release/obj.target/libusb/libusb/libusb/os/linux_udev.o
⠧ Building modules: 0/1  AR(target) Release/obj.target/usb.a
⠇ Building modules: 0/1  COPY Release/usb.a
  CXX(target) Release/obj.target/usb_bindings/src/node_usb.o
⠙ Building modules: 0/1In file included from /home/user/Projects/test/src/node_modules/usb/11.0.1/include/node/v8.h:30:0,
                 from ../src/node_usb.h:12,
                 from ../src/node_usb.cc:1:
/home/user/Projects/test/src/node_modules/usb/11.0.1/include/node/v8-internal.h: In function ‘void v8::internal::PerformCastCheck(T*)’:
/home/user/Projects/test/src/node_modules/usb/11.0.1/include/node/v8-internal.h:418:38: error: ‘remove_cv_t’ is not a member of ‘std’
             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
                                      ^~~~~~~~~~~
/home/user/Projects/test/src/node_modules/usb/11.0.1/include/node/v8-internal.h:418:38: note: suggested alternative: ‘remove_cv’
             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
                                      ^~~~~~~~~~~
                                      remove_cv
/home/user/Projects/test/src/node_modules/usb/11.0.1/include/node/v8-internal.h:418:38: error: ‘remove_cv_t’ is not a member of ‘std’
/home/user/Projects/test/src/node_modules/usb/11.0.1/include/node/v8-internal.h:418:38: note: suggested alternative: ‘remove_cv’
             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
                                      ^~~~~~~~~~~
                                      remove_cv
/home/user/Projects/test/src/node_modules/usb/11.0.1/include/node/v8-internal.h:418:50: error: template argument 2 is invalid
             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
                                                  ^
/home/user/Projects/test/src/node_modules/usb/11.0.1/include/node/v8-internal.h:418:63: error: ‘::Perform’ has not been declared
             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
                                                               ^~~~~~~
/home/user/Projects/test/src/node_modules/usb/11.0.1/include/node/v8-internal.h:418:63: note: suggested alternative: ‘perror’
             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
                                                               ^~~~~~~
                                                               perror
⠹ Building modules: 0/1In file included from ../src/node_usb.h:12:0,
                 from ../src/node_usb.cc:1:
/home/user/Projects/test/src/node_modules/usb/11.0.1/include/node/v8.h: At global scope:
/home/user/Projects/test/src/node_modules/usb/11.0.1/include/node/v8.h:9182:75: warning: ‘MicrotasksCompletedCallback’ is deprecated [-Wdeprecated-declarations]
   void AddMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
                                                                           ^
/home/user/Projects/test/src/node_modules/usb/11.0.1/include/node/v8.h:9190:78: warning: ‘MicrotasksCompletedCallback’ is deprecated [-Wdeprecated-declarations]
   void RemoveMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
                                                                              ^
⠼ Building modules: 0/1../src/node_usb.cc: In function ‘void handleHotplug(std::pair<libusb_device*, libusb_hotplug_event>)’:
../src/node_usb.cc:151:58: warning: ‘v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object>, const char*, int, v8::Local<v8::Value>*)’ is deprecated [-Wdeprecated-declarations]
  Nan::MakeCallback(Nan::New(hotplugThis), "emit", 2, argv);
                                                          ^
In file included from ../src/helpers.h:3:0,
                 from ../src/node_usb.h:21,
                 from ../src/node_usb.cc:1:
../../nan/nan.h:1001:46: note: declared here
   NAN_DEPRECATED inline v8::Local<v8::Value> MakeCallback(
                                              ^~~~~~~~~~~~
⠴ Building modules: 0/1usb_bindings.target.mk:128: recipe for target 'Release/obj.target/usb_bindings/src/node_usb.o' failed
make: *** [Release/obj.target/usb_bindings/src/node_usb.o] Error 1
make: Leaving directory '/home/user/Projects/test/src/node_modules/usb/build'
✖ Rebuild Failed

An unhandled error occurred inside electron-rebuild
node-gyp failed to rebuild '/home/user/Projects/test/src/node_modules/usb'.
Error: `make` failed with exit code: 2



Error: node-gyp failed to rebuild '/home/user/Projects/test/src/node_modules/usb'.
Error: `make` failed with exit code: 2


    at ModuleRebuilder.rebuildNodeGypModule (/home/user/Projects/test/node_modules/electron-rebuild/lib/src/module-rebuilder.js:193:19)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
child_process.js:669
    throw err;

如何构建

node-usb
模块以与 Electron 11.0.1 一起使用?我使用的是 Node 12.18.3,与 Electron 11.0.1 使用的版本相同,并且我在 Ubuntu 20.04 上运行此设置。这个包是我试图集成到应用程序中的 ant-plus 库的依赖项。

node.js electron antplus node-usb
1个回答
1
投票

Electron 11 有一个较新版本的 V8 JS 引擎,其本机模块

[email protected]
且 std 库的版本未设置为
std=c++14
,因此不支持 V8 现在所需的功能。

这是已知问题,您可以在这些 PR #376#394#400 中阅读相关内容,修复已于今天(2021 年 1 月 30 日)与此 PR #407 合并, NPM 上有新版本

[email protected]

现在,您的步骤在 Ubuntu 20.04 上适用,并且在安装最新的

ElectronRebuild.js
模块后,
usb
运行没有错误:

Ubuntu terminal success installing USB module

© www.soinside.com 2019 - 2024. All rights reserved.