opencv4nodejs icon indicating copy to clipboard operation
opencv4nodejs copied to clipboard

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

Open 64chevy opened this issue 3 years ago • 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.

64chevy avatar Mar 23 '21 13:03 64chevy

@74staz You might try this steps: https://github.com/justadudewhohacks/opencv4nodejs/issues/775#issuecomment-804347861

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.

KeitelDOG avatar Mar 23 '21 21:03 KeitelDOG

@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.

64chevy avatar Mar 27 '21 23:03 64chevy

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.

64chevy avatar Mar 28 '21 01:03 64chevy

@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.

KeitelDOG avatar Mar 28 '21 06:03 KeitelDOG

@74staz follow my suggestion here https://github.com/justadudewhohacks/opencv4nodejs/issues/775#issuecomment-804347861

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

KeitelDOG avatar Mar 28 '21 06:03 KeitelDOG

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

KeitelDOG avatar Mar 28 '21 06:03 KeitelDOG

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

Azperin avatar May 10 '21 14:05 Azperin

3. npm i -g npm@latest

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node ./install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

64chevy avatar May 10 '21 14:05 64chevy

add to package.json

"opencv4nodejs": {
	"disableAutoBuild": 1
} 

Azperin avatar May 10 '21 14:05 Azperin

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 

64chevy avatar May 10 '21 15:05 64chevy

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

Azperin avatar May 10 '21 15:05 Azperin

@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 https://github.com/justadudewhohacks/opencv4nodejs/issues/805 , I showed every step you need to do from where you are right now, after Tracking error. And you'll get it done.

KeitelDOG avatar May 10 '21 18:05 KeitelDOG

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.

Jiyvn avatar Sep 13 '21 14:09 Jiyvn

  1. brew update

  2. brew install opencv@4

  3. brew link --force opencv@4

  4. !!!NOTE!!! Please change the opencv version to fit your installation in step 3. export OPENCV4NODEJS_DISABLE_AUTOBUILD=1 export OPENCV_LIB_DIR=/opt/homebrew/Cellar/opencv/4.5.5_3/lib export OPENCV_BIN_DIR=/opt/homebrew/Cellar/opencv/4.5.5_3/bin export OPENCV_INCLUDE_DIR=/opt/homebrew/Cellar/opencv/4.5.5_3/include/opencv4

  5. npm install -g opencv4nodejs

ShawYN avatar Feb 20 '23 09:02 ShawYN

@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.

it dosen't work!

baibn avatar Mar 29 '24 07:03 baibn