I have cloned electron-react-boilerplate
from GitHub, which comes with Electron 11.0.1:
git clone --depth 1 --single-branch https://github.com/electron-react-boilerplate/electron-react-boilerplate.git test
Next, I install the template's dependencies by running yarn
. Everything installs, and yarn start
correctly starts the program.
Next, I try to install the node-usb
package with yarn add usb
within the src
folder, as instructed by the Electron documentation regarding the installation of native dependencies. The installation runs fine, after which yarn electron-rebuild
is automatically ran, executing the template's built-in ElectronRebuild.js
:
electron-rebuild --parallel --force --types prod,dev,optional --module-dir .
This fails due to the newly installed node-usb
package:
⠦ 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;
How can I build the node-usb
module for use with Electron 11.0.1? I am using Node 12.18.3, the same version Electron 11.0.1 is using, and I'm running this setup on Ubuntu 20.04. This package is a dependency of the ant-plus library I am trying to integrate into an application.
Electron 11 has a newer version of V8 JS engine which the native module usb@1.6.3
with a version of the std library not set to std=c++14
thus that doesn't support what V8 now requires.
This is known issue and you can read about it at these PRs #376, #394, #400 and the fix has been merged today (January 30 2021) with this PR #407 and there is a new release on NPM usb@1.6.4
.
Now your steps are working for me on Ubuntu 20.04 and ElectronRebuild.js
runs with no errors after installing latest usb
module: