justadudewhohacks/opencv4nodejs

new Error('library dir does not exist: ' + libDir)

64chevy opened this issue ยท 15 comments

Hello, I have been trying to install opencv4nodejs on MacOS Mojave with npm i opencv4nodejs and it keeps giving me this error:

npm ERR! code 1
npm ERR! path /Users/u/trr/node_modules/opencv4nodejs
npm ERR! command failed
npm ERR! command sh -c node ./install/install.js
npm ERR! info install using lib dir: /Users/u/trr/node_modules/opencv-build/opencv/build/lib
npm ERR! /Users/u/trr/node_modules/opencv4nodejs/install/install.js:37
npm ERR!   throw new Error('library dir does not exist: ' + libDir)
npm ERR!   ^
npm ERR! 
npm ERR! Error: library dir does not exist: /Users/u/trr/node_modules/opencv-build/opencv/build/lib
npm ERR!     at Object.<anonymous> (/Users/u/trr/node_modules/opencv4nodejs/install/install.js:37:9)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1092:14)
npm ERR!     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
npm ERR!     at Module.load (node:internal/modules/cjs/loader:972:32)
npm ERR!     at Function.Module._load (node:internal/modules/cjs/loader:813:14)
npm ERR!     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
npm ERR!     at node:internal/main/run_main_module:17:47

Have tried so many things but it just wouldn't work. Would be great if someone can help me with this.

@74staz You might try this steps: #775 (comment)

It will help you solve a lot. And then if your OpenCV installation is correct and matched opencv4nodejs version, than it will build fully. But quickly, you can just disable auto build in terminal with : export OPENCV4NODEJS_DISABLE_AUTOBUILD=1. And after you will build it yourself.

staz9 commented

@74staz You might try this steps: #775 (comment)

It will help you solve a lot. And then if your OpenCV installation is correct and matched opencv4nodejs version, than it will build fully. But quickly, you can just disable auto build in terminal with : export OPENCV4NODEJS_DISABLE_AUTOBUILD=1. And after you will build it yourself.

Thanks a lot, this looks really detailed. I switched to Python to work with OpenCV, now I am gonna try this for NodeJS.

staz9 commented

Okay so I installed it on my Mac but when I run it via require('opencv4nodejs') it gives this error:

/node_modules/opencv4nodejs/lib/cv.js:47
    throw err
    ^

Error: Cannot find module '/Users/u/trr/node_modules/opencv4nodejs/build/Release/opencv4nodejs'

The path exists but there is another folder "obj.target" like node_modules/opencv4nodejs/build/Release/obj.target/opencv4nodejs. Someone please help, thank you.

@74staz the file hasn't been created. There is some error on the node-gyp build. When its created, it will be a .node file under Release.
node_modules/opencv4nodejs/build/Release/oopencv4nodejs.node.

@74staz follow my suggestion here #775 (comment)

And this will increase greatly your chance to install it by understanding things better.

@74staz you might also try this if you want to use OpenCV 4.5.0:
httpss://github.com//issues/805#issuecomment-806314329

  1. npm i -g npm@6
  2. npm i opencv4nodejs --save
  3. npm i -g npm@latest
staz9 commented

3. npm i -g npm@latest

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! opencv-build@0.1.9 install: `node ./install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the opencv-build@0.1.9 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

add to package.json

"opencv4nodejs": {
	"disableAutoBuild": 1
} 
staz9 commented

add to package.json

"opencv4nodejs": {
	"disableAutoBuild": 1
} 

Ran into this now:

fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Release/obj.target/opencv4nodejs/cc/tracking/MultiTracker.o] Error 1
2 warnings generated.
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/User/.nvm/versions/node/v14.15.4/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
gyp ERR! System Darwin 18.7.0
gyp ERR! command "/Users/User/.nvm/versions/node/v14.15.4/bin/node" "/Users/User/.nvm/versions/node/v14.15.4/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--jobs" "max"
gyp ERR! cwd /Users/User/Desktop/test/node_modules/opencv4nodejs
gyp ERR! node -v v14.15.4
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 

Don't know how it works on Mac. Just install / build plain opencv. Make links in package.json, like mine, but with your paths:

"opencv4nodejs": {
"disableAutoBuild": 1,
"opencvIncludeDir": "R:\\OpenCV\\opencv\\build\\include",
"opencvLibDir": "R:\\OpenCV\\opencv\\build\\x64\\vc15\\lib",
"opencvBinDir": "R:\\OpenCV\\opencv\\build\\x64\\vc15\\bin",
"opencvDir": "R:\\OpenCV\\opencv\\build\\x64\\vc15"
} 

Then npm i opencv4nodejs --save

@staz9 then you are very close to it. But you need a bit of easy hacks like I did. First, forget about OpenCV version 4.5.1, that causes the Multitracker error, that has been moved to another directory and that this package did not know about this change.

With version 4.5.0, not Multitracker error, but you'll get SIFT error for sure in both versions. So as a hack, you will have to comment out 2 or 3 lines of code in modules source code to tell it to ignore the SIFT feature, which is now private and removed. Alternative for SIFT is SURF and 2 others. You will find SURF for sure, not sure for the 2 others. SURF is said to be faster in most use cases. And chances are you're not even gonna use any of them in your project. I didn't need their calculation, but SURF is still available.

You can follow this Issue #805 , I showed every step you need to do from where you are right now, after Tracking error. And you'll get it done.

Jiyvn commented
export OPENCV4NODEJS_DISABLE_AUTOBUILD=1

npm install -g opencv-build         // you might get error occur, try to set opencv4nodejs flag(https://github.com/justadudewhohacks/opencv4nodejs/issues/775#issuecomment-878141077)
npm install -g opencv4nodejs      // you should encounter an error, leave it out
sudo ln -s $(npm root -g)/opencv-build $(npm root -g)/opencv4nodejs/node_modules       // create a link of opencv-build under $(npm root -g)/opencv4nodejs/node_modules. remove if already exists
cd $(npm root -g)/opencv4nodejs/
node install/install.js         // complie error should be met, for me, it's `MultiTracker`

I finally got successful after comment out tracking related dependencies and xfeatures2d related dependencies in $(npm root -g)/opencv4nodejs/binding.gyp.

$(npm root -g)/opencv4nodejs/build/Release/opencv4nodejs.node will be generated, but unfortunately, I am not able to import opencv4nodejs module.