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

Viewed 7965

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'
3 Answers

For Mac users, if you are looking for a quick answer, you can edit the permissions of the .npm folder located at /Users/$(whoami)/.npm.

  1. Go to .npm parent folder (to prevent running the 2nd command in the wrong place).
$ cd /Users/$(whoami)
  1. Run chmod to change the permissions of the .npm folder.
$ sudo chmod -R 777 .npm/*

That's how I solved on my case.

In case anyone else arrives with a Mac cordova environment that has sudo'd itself beyond repair, this was my only solution (after a lot of pain):

  • backup everything
  • remove all cordova platforms (WARNING: this will wreck anything custom you've done within a platform, thus the backup)
  • uninstall cordova globally
  • uninstall npm; I just used the basic command from their site: sudo npm uninstall npm -g
  • install NVM
  • through that, install Node long-term-stable
  • install cordova (no more sudo required)
  • take permissions of your project directory (I did my whole user directory recursively)
  • add your platforms
  • diff back in any of your customizations
  • find a comfortable chair and drink scotch
Related