Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 of 3 tasks
NL33 opened this issue Apr 15, 2021 · 10 comments

Comments

@NL33
Copy link

NL33 commented Apr 15, 2021

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

@s1hofmann
Copy link
Member

Hi @NL33 👋

version 1.6.0 of nut.js is not compatible with Electron version > 8.x (see #166).

The @next snapshot already supports all recent Electron versions, but be aware that these are development releases:

npm i @nut-tree/nut-js@next

@NL33
Copy link
Author

NL33 commented Apr 15, 2021

Thanks very much @s1hofmann. After installing nut-js@next, I get this error when trying $ npm start:

App threw an error during load
Error: The module '/.../node_modules/opencv4nodejs-prebuilt/build/Release/opencv4nodejs.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 79. This version of Node.js requires
NODE_MODULE_VERSION 87. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).

I'm not really familiar with opencv4nodejs, but it must be some kind of very large module, no? When I had tried to install it with $ npm i opencv4nodejs, the installation took about 30 minutes (most packages take 30 seconds).

After getting the error above, I tried running $ npm rebuild, and it began another huge 30 minute process.

An hour of installations seems like overkill for me to test out the @next package. Am I missing something, or is this to be expected?

@svettwer
Copy link
Contributor

svettwer commented Apr 15, 2021

Nut.js comes with prebuilds of opencv to prevent the user from performing that 30 minutes build whenever an installation is done. For me it looks like the pre built does not match your node version.

Edit: After some google work, I found out that electron ships it's own node fork. Unfortunately I've no experience with that.

@s1hofmann
Copy link
Member

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.

@NL33
Copy link
Author

NL33 commented Apr 15, 2021

Thanks for your follow-up. It's very helpful.

Yes I am currently running node v 13.0.1.

I reverted the app to prior to going through the nut.js installation. So now the app is back to where it was prior.

I thought I'd try to go through the electron install again, so I just ran:

$ npm i @nut-tree/nut-js@next

And I got these errors:

npm ERR! code 1
npm ERR! path /.../node_modules/opencv4nodejs-prebuilt
npm ERR! command failed
npm ERR! command sh -c prebuild-install || (node ./install/dependencies.js && node ./install/install.js)
npm ERR! Installing prebuilt OpenCV vundefined for plattform darwin
npm ERR! prebuild-install WARN install No prebuilt binaries found (target=13.0.1 runtime=node arch=x64 libc= platform=darwin)
npm ERR! npm ERR! code ETARGET
npm ERR! npm ERR! notarget No matching version found for @nut-tree/opencv-build-darwin@undefined.
npm ERR! npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! npm ERR! notarget a package version that doesn't exist.
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /.../.npm/_logs/2021-04-15T...-debug.log
npm ERR! child_process.js:642
npm ERR!     throw err;

Do you recommend I do something different?

@s1hofmann
Copy link
Member

Hi @NL33 👋

The fastest thing you could do (if feasible for you) would be to switch to an LTS version of node (12 or 14) or the current latest version (15).
For these versions nut.js provides prebuilt node bindings so you don't have to compile them yourself on install.
Once installed, run the electron-rebuild step as described in the readme.

If you can't switch to a different node version you'd have to run the compilation once on install, but the electron-rebuild step will work just as fine. (Just tried it on my machine)

@NL33
Copy link
Author

NL33 commented Apr 15, 2021

It worked!

I just went ahead and upgraded Node to latest stable (node v 14.6.1).

Then, per your info:
$ npm i @nut-tree/nut-js@next
$ npm i -D electron-rebuild

package.json:

...
"scripts": {
    "rebuild": "electron-rebuild"
}
...

$ npm run rebuild

And from there no errors and I'm able to require nutjs in the app.

Thanks again.

@NL33 NL33 closed this as completed Apr 15, 2021
@s1hofmann
Copy link
Member

You're welcome 👍

@peec
Copy link

peec commented May 14, 2021

I stumbeled upon this issue for some days ago, i had to run

electron-rebuild -f -t prod,optional,dev for it to correctly build ( default -t does not include "dev").

...
"scripts": {
    "rebuild": "electron-rebuild -f -t prod,optional,dev"
}
...

@linonetwo
Copy link

linonetwo commented 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 #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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants