node-opencv: npm install opencv fails with "node-pre-gyp install --fallback-to-build"

Hello, I’ve searched far and wide on this forum, and on stack overflow for a way to solve this problem.

I have node version 4.6.1 npm version 3.10.9

OpenCV 2.4.13.1 was installed with brew at: /usr/local/Cellar

I’m trying to npm install opencv, but I get these errors:

C02QQKAQFVH5:~ TS98257$ sudo npm install opencv
Password:

> opencv@6.0.0 install /Users/TS98257/node_modules/opencv
> node-pre-gyp install --fallback-to-build

node-pre-gyp ERR! Tried to download(403): https://node-opencv.s3.amazonaws.com/opencv/v6.0.0/Release/node-v46-darwin-x64.tar.gz 
node-pre-gyp ERR! Pre-built binaries not found for opencv@6.0.0 and node@4.6.1 (node-v46 ABI) (falling back to source compile with node-gyp) 
/Users/TS98257/node_modules/opencv/utils/find-opencv.js:21
                throw new Error("ERROR: failed to run: pkg-config", opencv, flag);
                ^

Error: ERROR: failed to run: pkg-config
    at /Users/TS98257/node_modules/opencv/utils/find-opencv.js:21:23
    at ChildProcess.exithandler (child_process.js:220:5)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:829:16)
    at Socket.<anonymous> (internal/child_process.js:319:11)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at Pipe._onclose (net.js:486:12)
gyp: Call to 'node utils/find-opencv.js --cflags' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:305:16)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Darwin 14.5.0
gyp ERR! command "/opt/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/Users/TS98257/node_modules/opencv/build/opencv/v6.0.0/Release/node-v46-darwin-x64/opencv.node" "--module_name=opencv" "--module_path=/Users/TS98257/node_modules/opencv/build/opencv/v6.0.0/Release/node-v46-darwin-x64"
gyp ERR! cwd /Users/TS98257/node_modules/opencv
gyp ERR! node -v v4.6.1
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute 'node-gyp configure --fallback-to-build --module=/Users/TS98257/node_modules/opencv/build/opencv/v6.0.0/Release/node-v46-darwin-x64/opencv.node --module_name=opencv --module_path=/Users/TS98257/node_modules/opencv/build/opencv/v6.0.0/Release/node-v46-darwin-x64' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/Users/TS98257/node_modules/opencv/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at emitTwo (events.js:87:13)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:829:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
node-pre-gyp ERR! System Darwin 14.5.0
node-pre-gyp ERR! command "/opt/local/bin/node" "/Users/TS98257/node_modules/opencv/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /Users/TS98257/node_modules/opencv
node-pre-gyp ERR! node -v v4.6.1
node-pre-gyp ERR! node-pre-gyp -v v0.6.32
node-pre-gyp ERR! not ok 
Failed to execute 'node-gyp configure --fallback-to-build --module=/Users/TS98257/node_modules/opencv/build/opencv/v6.0.0/Release/node-v46-darwin-x64/opencv.node --module_name=opencv --module_path=/Users/TS98257/node_modules/opencv/build/opencv/v6.0.0/Release/node-v46-darwin-x64' (1)
npm WARN enoent ENOENT: no such file or directory, open '/Users/TS98257/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/Users/TS98257/node_modules/sshpk/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/Users/TS98257/node_modules/rc/package.json'
npm WARN TS98257 No description
npm WARN TS98257 No repository field.
npm WARN TS98257 No README data
npm WARN TS98257 No license field.
npm WARN In opencv@6.0.0 replacing bundled version of node-pre-gyp with node-pre-gyp@0.6.32
npm ERR! Darwin 14.5.0
npm ERR! argv "/opt/local/bin/node" "/usr/local/bin/npm" "install" "opencv"
npm ERR! node v4.6.1
npm ERR! npm  v3.10.9
npm ERR! code ELIFECYCLE

npm ERR! opencv@6.0.0 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the opencv@6.0.0 install script 'node-pre-gyp install --fallback-to-build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the opencv package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-pre-gyp install --fallback-to-build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs opencv
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls opencv
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/TS98257/npm-debug.log

I’m not sure what I’m doing wrong.

From what I’ve gathered, it has to do with my pkg-config. , however I followed the steps

My .bashrc file says this: PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH

Can anyone help?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 29

Most upvoted comments

I got my environment working on macOS, here are the steps:

  1. Install pkg-config and opencv@2: brew install pkg-config opencv@2.
  2. Link opencv: brew link opencv@2 --force.
  3. Remove node_modules and any lock files: rm -rf node_modules/.
  4. Run npm/yarn install: yarn.

I encountered a similar (but not this exact one) node-pre-gyp issue, and what (seemingly) helped was installing node-pre-gyp globally.

npm install node-pre-gyp -g

On WSL (Bash on Windows) I was able to fix the (similar) issue by installing libopencv-dev (see https://github.com/go-opencv/go-opencv/issues/57):

sudo apt-get install -y libopencv-dev

In my case apt-get first got issues with installing, I had to append the depends package names, too.

sudo apt-get install -y libopencv-dev libopencv-objdetect-dev libopencv-highgui-dev libopencv-legacy-dev libopencv-contrib-dev libopencv-videostab-dev libopencv-superres-dev libopencv-ocl-dev libcv-dev libhighgui-dev libcvaux-dev libgtk2.0-dev libpng-dev

I was experiencing the same issue but I managed to install it successfully.

OS: macOS 10.12 Sierra NPM: 3.10.8 Node: 7.0.0 Homebrew: 1.1.9 OpenCV: 2.4.13

I got it working by following @danschultzer 's suggestion and running: brew unlink opencv && brew link --overwrite opencv

It generated a whole load of warnings but seems to have been installed correctly.

Right from your log…

"…Please restart this script from an administrative PowerShell! The build tools cannot be installed without administrative rights. To fix, right-click on PowerShell and run “as Administrator”…

Sent from my iPhone

On Jan 7, 2017, at 10:40 AM, Saif Alabachi notifications@github.com wrote:

… and 1 more Downloaded python-2.7.11.msi. Saved to C:\Users\saifg.windows-build-tools\python-2.7.11.msi. Starting installation… Please restart this script from an administrative PowerShell! The build tools cannot be installed without administrative rights. To fix, right-click on PowerShell and run “as Administrator”.

I’ll recommend you guys to use OpenCV3 instead brew install opencv3; brew link --force opencv3

ninstall previous node.js and download load node version 8.4.0 Install and run .Hopefully the problem will be solve.

  1. clone node-opencv in folder node_modules
  2. npm install

that worked for me (Y)

Got it working on Windows 10!

Installed the windows build tools first: link.

Then ran npm install on the node-opencv clone I did and boom - it works. Tried some examples in the examples folder with success too. I am yet to use a lot of the stuff but this looks promising.

It does still worry me about the problems on non windows system builds, the lack of pre-node-gyp builds, and response from the maintainer - it’d be nice to know if this library is still supported.

Question:

node-pre-gyp ERR! Tried to download: https://node-opencv.s3.amazonaws.com/opencv/v5.0.0/Release/node-v46-win32-x64.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for opencv@5.0.0 and node@4.2.2 (node-v46 ABI) (falling back to source compile with node-gyp)

Is there a list of what pre-gyp binaries ARE out there so we can use nvm to get the right combination to avoid having to go through the build process?