Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM / Error: EACCES: permission denied, scandir [duplicate]

when i type "npm run build:prod"

build:prod
    npm run build -- --configuration production --aot --optimization=false

i get this error :

> [email protected] build:prod
> npm run build -- --configuration production --aot --optimization=false

glob error [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
 errno: -13,
 code: 'EACCES',
 syscall: 'scandir',
 path: '/root/.npm/_logs'
}
npm WARN logfile Error: EACCES: permission denied, scandir '/root/.npm/_logs'
npm WARN logfile  error cleaning log files [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
npm WARN logfile   errno: -13,
npm WARN logfile   code: 'EACCES',
npm WARN logfile   syscall: 'scandir',
npm WARN logfile   path: '/root/.npm/_logs'
npm WARN logfile }
⸨⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⸩ ⠙ : WARN logfile Error: EACCES: permission denied, scandir '/root/.npm/_logs'
> [email protected] build
> ng build "--configuration" "production" "--aot" "--optimization=false"

Node.js version v17.4.0 detected.file Error: EACCES: permission denied, scandir '/root/.npm/_logs'
Odd numbered Node.js versions will not enter LTS status and should not be used for production. For more information, please see https://nodejs.org/en/about/releases/.
This version of CLI is only compatible with Angular versions ^13.0.0-next || >=13.0.0 <14.0.0,ogs'
but Angular version 12.1.3 was found instead.

Please visit the link below to find instructions on how to update Angular.
https://update.angular.io/

i already try to delete node_module & package.json and run NPM install again, but it didnt work (Linux 4.19.0-16-cloud-amd64)

EDIT : solved with chown -R root /path/of/your/project

like image 412
euhjs Avatar asked Dec 15 '25 00:12

euhjs


1 Answers

Alternative approach: use a non-root user.

NPM is trying really hard (see other answer for details) to not execute anything as root. So what about trying just that - not being root? You would do something like this

  1. Add a local user (AMI guide), typically adduser john.doe --disabled-password
  2. Login as the new user sudo -s -u john.doe
  3. Clone your repo: git clone https://github.com/foo/bar; cd bar
  4. Run NPM command npm i;npm run build:prod
like image 58
oligofren Avatar answered Dec 16 '25 12:12

oligofren



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!