2

I was trying to install opencv4nodejs in Ubuntu-20.04 using the following command and my node version is v12.19.0

sudo npm i -g opencv4nodejs

But getting those errors

info install installing opencv version 3.4.6 into directory: /usr/lib/node_modules/opencv4nodejs/node_modules/opencv-build/opencv
ERR! Error: Command failed: mkdir -p opencv
mkdir: cannot create directory ‘opencv’: Permission denied
 
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.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-10-28T06_33_21_090Z-debug.log
Shahrear Bin Amin
  • 1,075
  • 13
  • 31

2 Answers2

5
  1. Running NPM install with sudo might be causing a permissions problem. You could try completely removing the node_modules directory and re-running NPM install it without sudo.

  2. Also make sure you have permission to write to the directory you're installing in?

  3. If it still doesn't work please follow this:

    sudo npm install -g opencv4nodejs --unsafe-perm=true --allow-root
    
Dharman
  • 30,962
  • 25
  • 85
  • 135
web-sudo
  • 701
  • 2
  • 13
1

This is complete guide to install opencv4nodejs to Linux OS or Raspberry pi (Raspberry Pi OS )

configuration

   01- sudo raspi-config  expand file system  // this is for raspberry pi 
   After Reboot (sudo reboot now)
   02- df -h (To check expand file system)
   03- sudo apt-get update && sudo apt-get upgrade -y
   04- sudo passwd root  // set up your root password
   Reboot

To Install NodeJS

   01- sudo apt-get install git -y
   02- curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -  // replase 12 with latest nodejs (LTS) version
   03- sudo apt-get install nodejs -y
   04- sudo apt-get install gcc g++ make

To Install opencv4nodejs

01. sudo apt-get install cmake -y
02. sudo npm install -g node-gyp

I am using this steps for raspberry pi os
03. sudo nano /etc/dphys-swapfile
    (Increase the CONF_SWAPSIZE from 100 to 1024)
        sudo /etc/init.d/dphys-swapfile stop
        sudo /etc/init.d/dphys-swapfile start

cd to home dir..
04. mkdir opencv
05. cd opencv
06. sudo npm init -y

07. su  
    // Enter your setup root password

08. sudo npm install --save opencv4nodejs

09. sudo nano /etc/dphys-swapfile
    (Set the CONF_SWAPSIZE back to 100)

In index.js and node_modules in same folder

const cv = require("opencv4nodejs");

In index.js and node_modules in not in same folder

const cv = require("path/opencv/node_modules/opencv4nodejs");

! you don't need to install opencv4nodejs for each folders You can simply call that above way

Hope guys you can understand it... Any questions feel free to ask...

Thank you