8

If I try and run the following in my docker setup

    docker-compose run --rm npm run dev

I get the following error

> dev
> npm run development

glob error [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
errno: -13,
code: 'EACCES',
syscall: 'scandir',
path: '/root/.npm/_logs'
 }

> development
 > cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide- 
 modules --config=node_modules/laravel-mix/setup/webpack.config.js

sh: 1: cross-env: not found
npm ERR! code 127
npm ERR! path /var/www/html
npm ERR! command failed
npm ERR! command sh -c cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js -- 
progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

Seems like a permissions issue but where how do I give permission for this, for root, uncertain where it is

This is the docker-compose.yml where I'm adding npm in docker so not sure where to give permission to /root/.npm/_logs as that seems to be in the application outside docker?

  version: '3'

  networks:
  laravel:

services:
 nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
  - "8080:80"
volumes:
  - ./src:/var/www/html
  - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
  - php
  - mysql
networks:
  - laravel

mysql:
image: mysql:5.7.22
container_name: mysql
restart: unless-stopped
tty: true
ports:
  - "3307:3306"
env_file:
  - src/.env
networks:
  - laravel

php:
build:
  context: .
  dockerfile: Dockerfile
container_name: php
volumes:
  - ./src:/var/www/html
ports:
  - "9000:9000"
networks:
  - laravel
npm:
 image: node:latest
container_name: npm
volumes:
  - ./src:/var/www/html
working_dir: /var/www/html
entrypoint: [ 'npm', '--no-bin-links' ]
networks:
  - laravel
5
  • I think you need to give permission to this folder /root/.npm/_logs. Commented Dec 1, 2020 at 14:58
  • Where and how ? Commented Dec 1, 2020 at 15:05
  • chmod -R 777 /root/.npm/_logs Commented Dec 1, 2020 at 15:07
  • There's nothing with that name in local machine, or docker containers with that folder name Commented Dec 1, 2020 at 15:16
  • Try updating your node docker image: docker pull node:latest Commented Jan 23, 2022 at 8:04

4 Answers 4

11

I faced the same issue while compiling assets form inside a docker container running a laravel app.

Background: I created the app to run as a docker container(following instructions on laravel docs), which uses laravel sail to build the containers. After creating and running the containers, i logged into the app container(i.e.;laravel.test).

  • Inside, I ran npm install to install node dependencies.
  • Ran npm run dev While webpack was able to successfully compile the assets, it also produced an error:
    glob error [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
      errno: -13,
      code: 'EACCES',
      syscall: 'scandir',
      path: '/root/.npm/_logs'
    }

Since the assets were successfully compiled, i assumed it's a notice-ish error, nothing major. Still i wanted to see if i could get rid of it.

How i got rid of it: When I entered the container, I was logged in as root. I looked up to see what other users are available in the system. I run cat /etc/passwd and noticed this line:

sail:x:1000:1000::/home/sail:/bin/bash

Which means sail was a user on the system. So on the shell, i ran su sail to change into sail user. Then ran npm run dev and the process finished successfully without producing that error.

    root@f0fec81c3439:/var/www/html# su sail
    sail@f0fec81c3439:/var/www/html$ npm run dev
Sign up to request clarification or add additional context in comments.

Comments

8

In your dockerfile, add a line with:

npm config set cache /tmp --global

Or any cache folder of choice.

3 Comments

We added mkdir /tmp/npm && chmod 2777 /tmp/npm && chown 1000:1000 /tmp/npm && npm config set cache /tmp/npm --global and solved a similar problem with another npm project.
@sneaky I'd recommend a small change to your suggestion. I'd flip the order of the last two commands and have it end with npm config set cache /tmp/npm --global && chown -R 1000:1000 /tmp/npm so that any file created when npm config is called ends up owned by the right user.
That sounds more correct than my solution.
7

I tried it with npm run --cache /var/cache/ COMMAND and the problem was fixed!

Comments

0

In my case, npm has been ugraded, I have to downgrade npm version

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.