Home > Net >  NPM / Error: EACCES: permission denied, scandir
NPM / Error: EACCES: permission denied, scandir

Time:02-02

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)

CodePudding user response:

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

CodePudding user response:

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:

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.

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.

  •  Tags:  
  • Related