19

When i try to install cypress using this commnad:

sudo npm install cypress

or

sudo npm install -g cypress

It is giving me this error:

Error: EACCES: permission denied, open '/Users/humac/node_modules/cypress/cypress.zip'

user10751590
  • 283
  • 2
  • 4
  • 11
  • Possible duplicate of [Permission denied when installing npm module](https://stackoverflow.com/questions/45520853/permission-denied-when-installing-npm-module) – abestrad Mar 13 '19 at 21:57
  • i tried but now getting this error ; Cypress cannot write to the cache directory due to file permissions ---------- Failed to access /Users/humac/Library/Caches/Cypress: EACCES: permission denied, mkdir '/Users/humac/Library/Caches/Cypress' ---------- Platform: darwin (17.7.0) – user10751590 Mar 13 '19 at 22:03

5 Answers5

35

Workaround: sudo npm install --unsafe-perm=true --allow-root cypress

20

In my case cypress had trouble accessing /root/.cache/Cypress upon npm install:

EACCES: permission denied, mkdir '/root/.cache/Cypress'

I found a relevant issue and ended up setting a custom cache dir:

export CYPRESS_CACHE_FOLDER=/app/.cache
npm install
thisismydesign
  • 21,553
  • 9
  • 123
  • 126
0

Try using yarn package manager or downgrading npm to version 7. For me it worked correctly.

I'm using Jenkins in an alpine linux container with node 16.

    stage('Prepare-build') {
    steps {
        sh 'node --version'
        sh 'npm --version'
        sh 'ls -p'
        sh 'git config --global --add safe.directory "*"'
        sh 'yarn install'
    }
}

The error I was getting is the following:

npm ERR! code 1
npm ERR! path /home/jenkins/agent/workspace/project/app/project-web-manager/node_modules/cypress
npm ERR! command failed
npm ERR! command sh /tmp/postinstall-716e113e.sh
npm ERR! Cypress cannot write to the cache directory due to file permissions
npm ERR! 
npm ERR! See discussion and possible solutions at
npm ERR! https://github.com/cypress-io/cypress/issues/1281
npm ERR! 
npm ERR! ----------
npm ERR! 
npm ERR! Failed to access /root/.cache/Cypress:
npm ERR! 
npm ERR! EACCES: permission denied, mkdir '/root/.cache/Cypress'
npm ERR! 
npm ERR! ----------
npm ERR! 
npm ERR! Platform: linux-x64 (Alpine Linux - 3.16.1)
npm ERR! Cypress Version: 10.6.0

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-08-18T17_09_27_887Z-debug-0.log

In my same case export the environment variable cypress cache folder did not work as expected, the error was even made mentioned above.

export CYPRESS_CACHE_FOLDER="/home/jenkins/agent/workspace/project/app/.cache"
0

After clearing my Cypress cache folder with cypress clear cache I ran into this issue as well.

This is what I did:

  1. sudo rm -rf the Cypress folder in your .cache directory
  2. For me I also deleted the Cypress folder in node_modules
  3. Cleaned cache with npm cache clean --force
  4. Installed Cypress with npm install cypress --save-dev

Hope this helps!

0

In my case I had issues running Cypress on Mac

An unexpected error occurred while verifying the Cypress executable.  

----------

Error: EACCES: permission denied, open '/Users/me/Library/Caches/Cypress/9.7.0/binary_state.json'

----------

Platform: darwin-x64 (22.2.0)
Cypress Version: 9.7.0

The easiest think to do is to locate the folder within Finder app, and for both "Cypress" and "9.7.0" folder and adjust the permissions for "everyone" and "staff" to "Read & Write".

Note: You must click on the lock icon and use your mac admin/system password to change the permissions.

changing permissions

Patronaut
  • 1,019
  • 10
  • 14