Reputation: 1213
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
Upvotes: 7
Views: 11074
Reputation: 89
In your dockerfile, add a line with:
npm config set cache /tmp --global
Or any cache folder of choice.
Upvotes: 8
Reputation: 536
I tried it with npm run --cache /var/cache/ COMMAND
and the problem was fixed!
Upvotes: 7
Reputation: 33
In my case, npm has been ugraded, I have to downgrade npm version
Upvotes: 0
Reputation: 1264
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).
npm install
to install node dependencies.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
Upvotes: 11