Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM/Cordova permissions Error: EACCES: permission denied, scandir

When I run cordova plugin add cordova-plugin-geolocation I receive the following error. I have tried enable 777 on this folder, setting myself as the owner etc. In these circumstances I'm not allowed to use sudo, but am confident if I could that would solve the problem.

Failed to install 'cordova-plugin-geolocation': Error: EACCES: permission denied, scandir '/Users/username/documents/core/myapp/app/platforms/ios/build/device/libCordova.a'
    at Error (native)
    at Object.fs.readdirSync (fs.js:952:18)
    at GlobSync._readdir (/Users/username/documents/core/myapp/app/platforms/ios/cordova/node_modules/glob/sync.js:275:41)
    at GlobSync._readdirInGlobStar (/Users/username/documents/core/myapp/app/platforms/ios/cordova/node_modules/glob/sync.js:254:20)
    at GlobSync._readdir (/Users/username/documents/core/myapp/app/platforms/ios/cordova/node_modules/glob/sync.js:263:17)
    at GlobSync._processReaddir (/Users/username/documents/core/myapp/app/platforms/ios/cordova/node_modules/glob/sync.js:135:22)
    at GlobSync._process (/Users/username/documents/core/myapp/app/platforms/ios/cordova/node_modules/glob/sync.js:130:10)
    at GlobSync._processGlobStar (/Users/username/documents/core/myapp/app/platforms/ios/cordova/node_modules/glob/sync.js:360:10)
    at GlobSync._process (/Users/username/documents/core/myapp/app/platforms/ios/cordova/node_modules/glob/sync.js:128:10)
    at GlobSync._processGlobStar (/Users/username/documents/core/myapp/app/platforms/ios/cordova/node_modules/glob/sync.js:363:10)
Error: EACCES: permission denied, scandir '/Users/username/documents/core/myapp/app/platforms/ios/build/device/libCordova.a'
like image 227
jskidd3 Avatar asked Jul 23 '17 18:07

jskidd3


1 Answers

NPM issue's

You can fix this problem using one of three options:

  1).Change the permission to npm's default directory.
  2).Change npm's default directory to another directory.
  3).Install node with a package manager that takes care of this for you.

You should back-up your computer before moving forward.

Option 1: Change the permission to npm's default directory

1).Find the path to npm's directory:

    npm config get prefix

For many systems, this will be /usr/local.

WARNING: If the displayed path is just /usr, switch to Option 2 or you will mess up your permissions.

2).Change the owner of npm's directories to the name of the current user (your username!):

  sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

This changes the permissions of the sub-folders used by npm and some other tools (lib/node_modules, bin, and share).

Option 2: Change npm's default directory to another directory

There are times when you do not want to change ownership of the default directory that npm uses (i.e. /usr) as this could cause some problems, for example if you are sharing the system with other users.

Instead, you can configure npm to use a different directory altogether. In our case, this will be a hidden directory in our home folder.

1).Make a directory for global installations:

 mkdir ~/.npm-global

2).Configure npm to use the new directory path:

 npm config set prefix '~/.npm-global'

3).Open or create a ~/.profile file and add this line:

 export PATH=~/.npm-global/bin:$PATH

4).Back on the command line, update your system variables:

 source ~/.profile

Test: Download a package globally without using sudo.

 npm install -g jshint

nstead of steps 2-4 you can also use the corresponding ENV variable (e.g. if you don't want to modify ~/.profile):

  NPM_CONFIG_PREFIX=~/.npm-global

Option 3: Use a package manager that takes care of this for you.

If you're doing a fresh install of node on Mac OS you can avoid this problem altogether by using the Homebrew package manager. Homebrew sets things up out of the box with the correct permission.

  brew install node
like image 141
Kondal Avatar answered Sep 20 '22 13:09

Kondal