gpt4 book ai didi

node.js - 为 Electron 构建 node-usb

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

我已经克隆了electron-react-boilerplate来自 GitHub,它带有 Electron 11.0.1:

git clone --depth 1 --single-branch https://github.com/electron-react-boilerplate/electron-react-boilerplate.git test
接下来,我通过运行 yarn 来安装模板的依赖项。 .一切都安装好了, yarn start正确启动程序。
接下来,我尝试安装 node-usbyarn add usb 打包在 src 内文件夹,如 Electron 文档中有关安装 native 依赖项的说明。安装运行良好,之后 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 的依赖项。我正在尝试集成到应用程序中的库。

最佳答案

Electron 11 具有更新版本的 V8 JS 引擎,其原生模块 usb@1.6.3 标准库版本未设置为 std=c++14因此这不支持 V8 现在需要的东西。
这是一个已知问题,您可以在这些 PR #376 上阅读相关内容, #394 , #400并且该修复程序已于今天(2021 年 1 月 30 日)与此 PR #407 合并NPM 上有一个新版本 usb@1.6.4 .
现在你的步骤对我有用 Ubuntu 20.04 ElectronRebuild.js安装最新的 usb 后运行没有错误模块:
Ubuntu terminal success installing USB module

关于node.js - 为 Electron 构建 node-usb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65871803/

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