The “Error: EACCES: permission denied, scandir” error can also occur when using NPM (Node Package Manager) and trying to install a package. This is because NPM needs to access certain directories on your system, such as log files under the home directory or the global node_modules directory, and the error occurs when it doesn’t have the proper permissions to do so.

The Problem:

While running the npm command, I faced the following error message.

NPM error message:

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

Generally, users receive this error, while running the npm commands with the root account. Here, we will discuss two solutions to resolve this error message.

Solution 1:

It is recommended not to run the npm command as the root account. This can be harmful to your system. So you can simply switch to a non-root account and run the same command.

Most probably this will resolve your issue.

Solution 2:

If you are bound to run the npm command as the root account. Then make sure the current working directory, in which you are running the npm command is owned by the root account.

So, change the current working directory (CWD) owner to root.

chown root:root . 

Then run your npm commands, and it should run without any error.

Conclusion

In summary, the “Error: EACCES: permission denied, scandir” error can occur when using NPM if the user does not have the proper permissions to access a specific directory. In this article, we have discussed two solutions to resolve this error on your system.