opencv4nodejs not installing in MAC OS Mojave 10.14

What I Wanted to Do

sudo npm install -g opencv4nodejs

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/string_decoder-5df191d0/lib’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/delegates-0faee5cf/test’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv-build-e21e20eb/install’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/b9/73’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/4e/45’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/59/51’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/ea/57’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/77/b2’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/d5/38’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/b2/c6’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/21/5c’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/d5/38’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/a5/3e’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/60/8c’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/16/ea’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/1d/66’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/f5/6d’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/32/57’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/bf/10’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/eb/cb’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/77/61’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc/core’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/readable-stream-86cdaefa/doc/wg-meetings’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/readable-stream-86cdaefa/lib’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/readable-stream-86cdaefa/lib/internal/streams’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/nan-9548b56c/doc’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc/cvTypes’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/nan-9548b56c/tools’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc/modules/calib3d’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc/modules/dnn’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc/modules/face’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc/modules/features2d’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc/modules/features2d/detectors’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc/modules/imgproc’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc/modules/io’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc/modules/machinelearning’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc/modules/objdetect’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc/modules/photo’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc/modules/text’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc/modules/tracking’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc/modules/tracking/Trackers’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc/modules/video’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc/modules/xfeatures2d’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/cc/modules/ximgproc’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/lib’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/lib/haarcascades’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/macro-inferno-c7e47df9/src’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/22/e6’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/core-util-is-fbc4f3f3/lib’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/46/b3’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/lib/lbpcascades’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/lib/src’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/79/db’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/opencv4nodejs-3f4e1522/lib/typings’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/dc/f6’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/ed/b8’

npm WARN tar EISDIR: illegal operation on a directory, open ‘/usr/local/lib/node_modules/.staging/native-node-utils-a7ca06f8/src’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/ff/02’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/6c/6f’

Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/rohit/.npm/_cacache/index-v5/b6/46’

npm ERR! cb() never called!

npm ERR! This is an error with npm itself. Please report this error at:

npm ERR! <https://npm.community>

npm ERR! A complete log of this run can be found in:

npm ERR! 2019-02-01T11_17_12_668Z-debug.log (36.8 KB)
/2019-02-01T11_17_12_668Z-debug.log

Details

$ node -p process.platform

Hello, you shouldn’t be using sudo to run npm commands. Use a version manager like nvm instead if you can’t bypass that for some reason. This is also becoming a more standardized way of using npm.

As for your error, npm is trying to write to a file, which is actually a directory, resulting in the EISDIR error. I’ve only seen this with global packages.

Another idea would be to maintain all of your packages in your local project and reference the necessary commands with npm scripts.

Rohit I am not sure if you will need to delete some caches to repair the problem, so this suggestion may not work alone. The goal is to avoid the use of sudo, partly for security, and partly because it complicates things with npm.

If this is your personal computer, I suggest you change the ownership of the relevant directories to yourself so that you do not need to use sudo to install npm global modules. Taking ownership of /usr/local is the approach that homebrew uses, and I do this myself. The first command is to also reclaim ownership of the files in your own directory (as using sudo may have left some files owned by root).

sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) /usr/local/lib
sudo chown -R $(whoami) /usr/local/bin

Then try your command again without sudo:

npm install -g opencv4nodejs

Note: after running an install of node using the installer from nodejs you will need to rerun the chown commands to reclaim ownership of the /usr/local directories.

Other approaches to avoid the use of sudo are as Brian suggested, installing the package locally, or installing global modules to your own directory such as by using a node version manager.

The canonical topic to refer to is: Global installs (sudo npm i -g) fail on Mac after 6.5 upgrade. Works fine after 6.4.1 downgrade.

Downgrading npm to 6.4.1 solves the issue for some people.

And I just found a good summary post from @larsgw in this comment:

I got the info when i run the command: npm i -g opencv4nodejs;
can anyone help me to fix the problem?thanks a lot
modules/dnn/CMakeFiles/opencv_dnn.dir/layers/layers_common.avx2.cpp.o
[ 75%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/layers/layers_common.avx512_skx.cpp.o
[ 75%] Linking CXX shared library …/…/lib/libopencv_dnn.dylib
[ 75%] Built target opencv_dnn
make: *** [all] Error 2
ERR! child process exited with code 2 (for more info, set ‘–loglevel silly’)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! opencv-build@0.0.17 install: node ./install.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the opencv-build@0.0.17 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/xxx/.npm/_logs/2019-02-24T10_06_35_829Z-debug.log

@rohitptwl hi~have you installed the opencv4nodejs?

@ManningZhang
Your problem is a build failure rather than an issue with npm, so a different problem than the original poster in this topic.

You are likely to get more help in the opencv4nodejs context, and I see their GitHub issues template includes explicit guidance about reporting build problems, which is a good sign for getting help: https://github.com/justadudewhohacks/opencv4nodejs/issues

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.