question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cypress cannot write to the cache directory due to file permissions in Bitbucket pipeline

See original GitHub issue

Current behavior

When running npm install in bitbucket pipelines, this happens:

> cypress@6.4.0 postinstall /opt/atlassian/pipelines/agent/build/node_modules/cypress
> node index.js --exec install
Cypress cannot write to the cache directory due to file permissions
See discussion and possible solutions at
https://github.com/cypress-io/cypress/issues/1281
----------
Failed to access /root/.cache/Cypress:
EACCES: permission denied, mkdir '/root/.cache/Cypress'
----------

Desired behavior

Don’t write to the root directory. This should be fixed since 4.6.0, according to #1281

Test code to reproduce

Create a Bitbucket repository, enable pipelines, do npm i in the Bitbucket pipeline.

Versions

6.4.0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:8
  • Comments:9

github_iconTop GitHub Comments

1reaction
marcosaguilera-globercommented, Sep 5, 2022

I was getting same issue: # EACCES: permission denied, mkdir ‘/root/.cache/Cypress’

I’ve fixed like this:

  1. In my Dockerfile
#Cypress version using
FROM cypress/included:10.6.0

# Installing sudo for superower installation required
# into entrypoint.sh
RUN apt-get install sudo

# Directories actions
WORKDIR /home/pwsh/tempVolume

ENTRYPOINT ["/bin/sh", "./entrypoint.sh"]
  1. In my entrypoint.sh script file
#!/bin/sh
echo "I'm into the sh file"

## Install packages defined into package.json > dependencies node
##npm install
sudo npm install --unsafe-perm=true --allow-root

## Run cypress
cypress run

I messed up a time with this issue, and I tried with permissions chown node:node, also some chmod -R 777, but nothing worked for me, so I installed sudo apt-get into Linux distro.

Hope this help anyone.

0reactions
gustavodamaziocommented, Aug 18, 2022

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"
Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting
Open Cypress via cypress open · Go to Developer Tools -> View App Data · This will take you to the directory in...
Read more >
Getting error "EACCES: permission denied" when i install ...
Cypress cannot write to the cache directory due to file permissions npm ERR! npm ERR! See discussion and possible solutions at npm ERR!...
Read more >
cypress-io/cypress - Gitter
... --exec install Cypress cannot write to the cache directory due to file permissions ---------- Failed to access /Users/anilyadav/Library/Caches/Cypress: ...
Read more >
Caches | Bitbucket Cloud
Bitbucket Pipelines is able to cache external build dependencies and directories between builds, to reduce consumed build minutes.
Read more >
Caching Dependencies
Warning: Caching files between different executors, for example, between Docker and machine, Linux, Windows or macOS, or CircleCI image and non-CircleCI image, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found