question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't Install with Electron (Mac Big Sur). Error: Cannot find module "node_modules/opencv4nodejs-prebuilt/build/Release/opencv4nodejs"

See original GitHub issue

Version @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:closed
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
s1hofmanncommented, Apr 15, 2021

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:

  • You’re running node 13 on your machine
  • On install it re-compiled opencv4nodejs for node 13, since there are no prebuilds for this version available (according to NODE_MODULE_VERSION 79)
  • You did not run a custom rebuild script via npm run rebuild as shown in the nut.js readme but npm 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 as NODE_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 run npx electron --abi in your project.

Ok, so how does this work in nut.js?

nut.js or more specifically opencv4nodejs-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.

0reactions
linonetwocommented, Oct 27, 2021

I get

NODE_MODULE_VERSION 89. This version of Node.js requires NODE_MODULE_VERSION 98. Please try re-compiling or re-installing

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 and npm i @nut-tree/nut-js@next and rerun npm i after delete opencv4nodejs-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”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't install on mac m1 · Issue #485 · electron ... - GitHub
mac m1 Mac OS Big Sur 11.1. What version of Node.js is on your system? v15.5.1. My Issue: Error occured when running "npm...
Read more >
Not able to globally install electron on MacOS due to error
Going back in Electron's releases page, I cannot seem to find any darwin-ia32 assets (darwin is the codeame for macOS).
Read more >
Fix Global Installs Not Working | "Cannot find module" error FIX
Getting " Cannot find module " after installing something globally (with -g)? Well, this video shows you how to fix global package/module ...
Read more >
Electron app on Apple silicon using Rosetta2?
Hi, I'm trying to get our Electron app running on Apple Silicon Mac. Running a beta release of macOS Big Sur on our...
Read more >
Getting erron when building on Mac - Electron
Hi there! Describe When I run a build script for Mac got an error > yes|cp -R -H ../sdk/mac/Plugins .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found