Error: EACCES: permission denied, scandir '/root/.npm/_logs'

#1

I’ve setup a project and run with the simple config file given during the install process.

# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/node:7.10

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/mongo:3.4.4

    working_directory: ~/repo

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-

      - run: yarn install

      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}

      # run tests!
      - run: yarn test

This resulted in a permissions error. I’ve managed to move on by adding sodu before the yarn install command. Now I have another issue - in the karma postinstall, I get another permission error:

> webpack-karma-jasmine@3.0.6 postinstall /home/circleci/repo/node_modules/webpack-karma-jasmine
> npm install karma-cli -g

npm ERR! path /root/.npm/_logs
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall scandir
npm ERR! Error: EACCES: permission denied, scandir '/root/.npm/_logs'
npm ERR!  { Error: EACCES: permission denied, scandir '/root/.npm/_logs'
npm ERR!   stack: 'Error: EACCES: permission denied, scandir \'/root/.npm/_logs\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'scandir',
npm ERR!   path: '/root/.npm/_logs' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.
glob error { Error: EACCES: permission denied, scandir '/root/.npm/_logs'
  stack: 'Error: EACCES: permission denied, scandir \'/root/.npm/_logs\'',
  errno: -13,
  code: 'EACCES',
  syscall: 'scandir',
  path: '/root/.npm/_logs' }
npm ERR! path /root/.npm/_cacache/index-v5/db/af/3c36804ee49875846a6f89401c5793623ad4d3160812228c88186cb2576a
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open
npm ERR! Error: EACCES: permission denied, open '/root/.npm/_cacache/index-v5/db/af/3c36804ee49875846a6f89401c5793623ad4d3160812228c88186cb2576a'
npm ERR!  { Error: EACCES: permission denied, open '/root/.npm/_cacache/index-v5/db/af/3c36804ee49875846a6f89401c5793623ad4d3160812228c88186cb2576a'
npm ERR!   cause: 
npm ERR!    { Error: EACCES: permission denied, open '/root/.npm/_cacache/index-v5/db/af/3c36804ee49875846a6f89401c5793623ad4d3160812228c88186cb2576a'
npm ERR!      errno: -13,
npm ERR!      code: 'EACCES',
npm ERR!      syscall: 'open',
npm ERR!      path: '/root/.npm/_cacache/index-v5/db/af/3c36804ee49875846a6f89401c5793623ad4d3160812228c88186cb2576a' },
npm ERR!   isOperational: true,
npm ERR!   stack: 'Error: EACCES: permission denied, open \'/root/.npm/_cacache/index-v5/db/af/3c36804ee49875846a6f89401c5793623ad4d3160812228c88186cb2576a\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'open',
npm ERR!   path: '/root/.npm/_cacache/index-v5/db/af/3c36804ee49875846a6f89401c5793623ad4d3160812228c88186cb2576a' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

For some reason, it doesn’t happen with other projects with the exact same setup (both are using karma and karma-jasmine with the same image - circle-ci/node:9.5-browsers).

Any idea how to get over this issue?

#2

sudo is often going to cause permissions issues. Can you try removing it every place you have added it, and rolling your cache keys to v2-?

#3

I started without sudo but it gave me an error as well, so sudo was a solution from stackoverflow.
Here’s what happens without sudo:
https://circleci.com/gh/YonatanKra/web-components-ui-elements/16

#5

Hi,

Can you try the following two things?

  1. Temporarily disable caching. You can just comment the cache and restore related lines.
  2. Only use sudo to install karma globally. Don’t use sudo when running npm install and npm test/yarn test.
1 Like