Can't Install with Electron (Mac Big Sur). Error: Cannot find module "node_modules/opencv4nodejs-prebuilt/build/Release/opencv4nodejs"
See original GitHub issueVersion @nut-tree/nut-js: 1.6.0 electron: 12.0.2 electron-rebuild: 2.3.5 node-gyp: 8.0.0 opencv4nodejs: 5.6.0 Mac OS: 11.1
Short overview
I am trying to get nut.js to work with electron (my machine: Mac, OS 11.1). I have gone through the installation steps, but when I go to start the app, I continually get the error:
Cannot find module "node_modules/opencv4nodejs-prebuilt/build/Release/opencv4nodejs"
.
If I try to run $ npm run rebuild
, I get the error:
An unhandled error occurred inside electron-rebuild
node-gyp failed to rebuild '/.../node_modules/opencv4nodejs'.
Error: `make` failed with exit code: 2
Issue occurs on
- Virtual machine
- Docker container
- Dev/Host system
Detailed error description
I have gone through the installation steps for Electron and Mac. Including (in my electron app):
$ npm i @nut-tree/nut-js
$ npm i -D electron-rebuild
And then attempted to run
$ npm i electron-rebuild
but got error:
Error: node-gyp failed to rebuild '/.../node_modules/opencv4nodejs'.
Error: `make` failed with exit code: 2
at ModuleRebuilder.rebuildNodeGypModule (/.../node_modules/electron-rebuild/lib/src/module-rebuilder.js:193:19)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
I then installed additional items:
$ xcode-select --install
$ npm install opencv4nodejs
$ npm install node-gyp
All installed without error. But even after these steps, I still get the node gyp error above whenever I run $ npm run rebuild
.
And if I try $ npm start
I get the error:
App threw an error during load
Error: Cannot find module '/.../node_modules/opencv4nodejs-prebuilt/build/Release/opencv4nodejs'
Steps to reproduce error See above description of steps I’ve taken.
Additional content
N/A
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (5 by maintainers)
Hi @NL33 👋
I ran a small sample using Electron 12 with
@nut-tree/nut-js@next
on my Big Sur machine and can confirm it works as expected and the installation process went quite fast and smoothly.Did you follow the Electron usage guide?
Given your description of a 30 minutes installation process I’m assuming some things, please correct me if I’m wrong:
install
it re-compiledopencv4nodejs
for node 13, since there are no prebuilds for this version available (according to NODE_MODULE_VERSION 79)rebuild
script vianpm run rebuild
as shown in the nut.js readme butnpm rebuild
, otherwise it should download prebuilds for your Electron version (according to the required NODE_MODULE_VERSION 87)Additional infos, skip if not interested
I’m not familiar with native node addons, could you explain a bit?
opencv4nodejs-prebuilt
provides node bindings for OpenCV via native abstractions for node (a.k.a.nan
).The problem with
nan
based bindings is the fact that they rely on a specific application binary interface (ABI), since they are directly calling e.g. V8 functions. Unfortunately, this ABI is not stable across multiple node versions, so we need to compile our native addon for each version of node we want to use it with. These ABI versions are referred to asNODE_MODULE_VERSION
and this list of node releases shows which node versions uses which ABI.Since Electron is not exactly node, it comes with a slightly different ABI, so in order to use a
nan
module with Electron, we have to build it for the specific ABI. An easy way to check the ABI version of your Electron version in use is to runnpx electron --abi
in your project.Ok, so how does this work in
nut.js
?nut.js
or more specificallyopencv4nodejs-prebuilt
provides prebuilt bindings for all current LTS versions of node as well as several version of Electron.You can verify this on the latest release of opencv4nodejs-prebuilt. There are several assets storing precompiled addons for multiple node / Electron versions for Windows / Linux / macOS.
opencv4nodejs-prebuilt-v5.3.1-electron-v87-darwin-x64.tar.gz
would be the correct prebuild for Electron v12 on macOS.electron-rebuild
would download this archive from the GitHub release and extract it to your project, skipping a recompilation.I get
As stated in https://github.com/nut-tree/nut.js/discussions/300
And I tried
electron-rebuild -f -t prod,optional,dev
and use LTS nodeJS andnpm i @nut-tree/nut-js@next
and rerunnpm i
after deleteopencv4nodejs-prebuilt
in the node_modules several times.But it still not working…
Or…Does this precompiled binary work in electron@15 now? If not, how to recompile? Can you add it to the readme? I can see there is only prerequisite in https://github.com/nut-tree/nut.js#manual-build, but no “how to trigger manual rebuild”