justadudewhohacks / opencv4nodejs

Nodejs bindings to OpenCV 3 and OpenCV 4
MIT License
4.92k stars 813 forks source link

JS error when running electron app on another computer #535

Open stoefln opened 5 years ago

stoefln commented 5 years ago

I am using opencv4nodejs in my electron app.

When I package the app and try to run it on another computer I am getting following error:

A JavaScript error occurred in the main process
Uncaught Exception:
Error: dlopen(/var/folders/7m/klqbsvis2iqg_mb_pdvv79fhO000gn/
T/.app.repeato.uuz70R, 1): Library not loaded: @rpath/
libopency_core.3.4.dylib
 Referenced from: /var/folders/7m/kiqbsvis2iqg_mb_pdvv79fhOG00gn/
Tf.app.repeato.uuz70R
 Reason: image not found
  at process.module.(anonymous function) (as dlopen} (ELECTRON_ASAR.js:166:20)
  at Object.Module._extensions..node (internal/modules/cjsfosder.js:740:18)
  at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:180:18)
  at Module.load (internal{modules/cjsfoader.js:620:32)
  at tryModuleLoad (internal/modules/cjs/loader.js:559:12)
  at Function.Madule._load {internal/modules/cjs/loader.js:551:3)
  at Module.require (internal/modules/cjs/loader.js:658:17)
  at require (internal/modules/cjs/helpers.js:20:18)
  at Object.<anonymous> (/Applications/Repeato.app/Contents/Resources/app.asar/node_modules/opencv4nodejs/lib/cv.js:17:8)
  at Object.<anonymous> (/Applications/Repeato.app/Contents/Resources/app.asar/node_modules/opencv4nodejs/lib/cv.js:28:3)

Any ideas what's wrong? I found a very similar issue on github, but not sure if it really is

stoefln commented 5 years ago

After spending weeks on trying to figure out what's wrong, I've made some progress and I am able to build for osx now. Still struggling on windows. One thing I can tell for sure: Bundling opencv4electron for windows requires a lot of additional effort (copying libraries around etc.). Hit me up if you want to get my script...

gallagherrchris commented 4 years ago

@stoefln I'm running into some issues with opencv4nodejs inside of electron. Could you share what you did to make it work? I'm trying to go down the electron-forge path.

stoefln commented 4 years ago

@gallagherrchris: I got a lot of useful hints from this project: https://github.com/fakob/MoviePrint_v004 do you have troubles with win or mac?

gallagherrchris commented 4 years ago

I have troubles on both. I created a small project showing my issue.

https://github.com/gallagherrchris/opencv4nodejs-electron-test

This project won't start as it can't find the opencv4nodejs module.

I noticed that the project you linked is using electron 4. I was trying to stick with electron-forge as that means I wouldn't have to configure as much myself. Perhaps that is my mistake.

stoefln commented 4 years ago

@gallagherrchris I also had some other issues with electron 5, so I stuck with electron 4 for now. I am not using electron forge btw. My problem was that there were dependencies missing. The error "module not found" is misleading. What it actually should say is "Module or some of its dependencies not found". In my case it was a dependency issue. I wrote a script which packages the missing opencv dependencies into the electron app. Uploaded it here: https://gist.github.com/stoefln/ed1b0a63e229438f54a86ab7ad277073

For windows it was enough for me to add this configuration to the package.json: https://github.com/fakob/MoviePrint_v004/blob/master/package.json#L106-L112

Let me know if you keep having troubles....

zcmgyu commented 3 years ago

I have almost the same your issue, and this is my attempt

https://github.com/justadudewhohacks/opencv4nodejs/issues/707#issuecomment-686993124