CircleCI-Public / node-orb

An orb for working with Node.js on CircleCI
https://circleci.com/orbs/registry/orb/circleci/node
MIT License
52 stars 80 forks source link

Permission denied while restore npm cache #158

Open lu911 opened 2 years ago

lu911 commented 2 years ago

Orb version: 5.0.2

What happened:

Getting "Permission Denied" while restore npm cache.

error:

Found a cache from build 859 at node-deps-arch1-linux-amd64-6_106-v2-develop-XdJ1g_ahUn0RDtSmEalhzFrcTZXR2yOAu+BGa+T52zI=
Size: 61 MiB
Cached paths:
  * /home/circleci/.npm

Downloading cache archive...
Validating cache...

Unarchiving cache...
Skipping writing "home/circleci/.npm/_cacache/content-v2/sha1/04/5f/9782d011ae9a6803ddd382b24392b3d890f7" - open /home/circleci/.npm/_cacache/content-v2/sha1/04/5f/9782d011ae9a6803ddd382b24392b3d890f7: permission denied

config.yml:

version: 2.1
orbs:
  node: circleci/node@5.0.2

jobs:
  deploy:
    working_directory: ~/tmp
    machine:
      image: ubuntu-2004:202201-02
    steps:
      - checkout
      - attach_workspace:
          at: ~/tmp
      - node/install:
          node-version: '14.17.3'
      - node/install-packages:
          override-ci-command: npm install
          cache-version: v3
      - deploy:
          name: Deploy
          command: |
            ...

Expected behavior:

The cache is restored without errors.

Additional Information:

whanwells commented 1 year ago

This seems to only occur when using a machine image (at least in my experience).

eaviles commented 1 year ago

I was having this issue too, in my experience it seems like when using a machine image it sometimes picks up hosts with cached files from other pipeline runs. I got around the issue by deleting the ~/.npm folder before trying to restore the cache…

- run: rm -rf ~/.npm
- node/install-packages

Funny enough, it seems to happen with other tools like nvm. The cache (/opt/circleci/.nvm/.cache) has already a bunch of files when starting the machine.

whanwells commented 1 year ago
- run: rm -rf ~/.npm
- node/install-packages

This worked for me as well. Thanks for the tip @eaviles!

KyleTryon commented 1 year ago

Hey folks, sorry for the delay. I have replicated the issue and working with the image folks to see what we can do.

Peter-Darton-i2 commented 1 year ago

I ran into this one too. chmod -R u+w ~/.npm sorted it for me. I wouldn't recommend nuking the folder.

As far as I can tell, this is actually a symptom of flaws in the restore_cache functionality; if that was made to work correctly, this wouldn't be a problem.

DominicGBauer commented 1 year ago

@KyleTryon has there been any progress on this issue?

KyleTryon commented 1 year ago

This image had been resolved, we should have closed this issue. Are you experiencing this again? Is it also on the machine? @DominicGBauer

warrenronsiek commented 1 month ago

I'm experiencing this issue with the following:

jobs:
  test:
    docker:
      - image: cimg/node:21.7.1
    steps:
      - checkout
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "yarn.lock" }}

the proposed workarounds don't work for me: '/home/circleci/.npm': No such file or directory

marboledacci commented 2 weeks ago

@warrenronsiek can you provide more details on the issue you have? The exact error, the orb version. The original issue was related to machine executors, so your issue is probably different.