Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

880
Views
NPM / Error: EACCES: permission denied, scandir

when i type "npm run build:prod"

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

i get this error :

> fancy-name@0.0.0 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'
> fancy-name@0.0.0 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

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

This is understandably a confusing error; you run npm as root, and yet it says you do not have access to the files? There is a good reason :) These questions are essentially about the same thing:

  • fs.readFileSync throwing EACCESS when called using `npm`, but not using `node`
  • Bower install EACCESS error

My quite long answer goes into details on what is happening, but the essence is this:

(NPM) ... uses this bit of code to determine who to run as:

const { uid, gid } = isRoot ? inferOwner.sync(cwd) : {}

and as the docs of infer-owner module says: Infer the owner of a path based on the owner of its nearest existing parent

So if you are running NPM as root you need to change the owner of the current directory to root as well:

chown -R root /path/of/your/project

But all this trouble should point you to the real solution: do not run NPM as root. You have no idea what kind of scripts might run as a postinstall trigger or similar. Be safe; only use the root account when necessary using sudo.

Addendum: try Node 14

As mentioned in the linked answer:

This behavior is only for NPM versions >= 7. NPM versions < 7, which are the ones shipped with Node 12-14 work perfectly fine when running as root. So the quickest fix might simply be to use Node 14.

  • npm install -g nvm
  • nvm use 14
about 4 years ago · Juan Pablo Isaza Report

0

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
about 4 years ago · Juan Pablo Isaza Report

0

glob error [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {

This means it is trying to read something on 'root' directory, something which always needs root access.

Try to run the command like this:

sudo npm run build:prod

Extra: Usually you should NOT run commands with sudo. If you come from a Windows background think of it as 'Run as administrator', only with even more privileges, so if you are running a malicious script it could have access to almost everything on your system. There are ofc some JS libraries which need root/sudo access to do their things tho

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!