Matched signals
- npm ERR! code EACCES
- EACCES: permission denied
- permission denied.*node_modules
- Error: EACCES: permission denied
- Please try running this command again as root/Administrator
npm EACCES permission denied in node_modules
What this failure means
npm failed with an EACCES error while trying to write to node_modules or the global npm cache.
Symptoms
Faultline looks for one or more of these log fragments:
npm ERR! code EACCES
EACCES: permission denied
permission denied.*node_modules
Error: EACCES: permission denied
Please try running this command again as root/Administrator
Diagnosis
npm needs write permission to the node_modules directory and the global npm cache. This error occurs when the CI runner or container runs under a user that lacks those permissions.
Common causes:
- The
node_modulesdirectory is owned by a different user (e.g., from a previous run withsudo). - The CI job runs as
rootbut npm is configured to reject root installs. - A Docker volume mounts
node_moduleswith incorrect ownership. - The npm cache directory (
~/.npm) is read‑only.
Fix steps
-
Clean and reset permissions (if
node_modulesalready exists):rm -rf node_modules rm -rf package-lock.json -
Ensure the current user owns the project directory:
sudo chown -R $(whoami):$(whoami) . -
If running in Docker, avoid root:
- Use the
nodeofficial image’s non‑root user (e.g.,node:20-alpine). - Set
USER nodein your Dockerfile beforenpm install.
- Use the
-
If you must run as root, configure npm to allow it:
npm config set unsafe-perm true -
Check npm cache permissions:
npm cache verify ls -la ~/.npm -
Use
npm ciinstead ofnpm installwhen apackage-lock.jsonexists; it is stricter and may avoid some permission issues. -
In CI, run as a non‑root user by adding a step:
useradd -m -u 1001 ci-user chown -R ci-user . su ci-user -c "npm install"
Validation
ls -la node_modulesshows the directory is writable by the current user.- Re‑run the npm command and confirm no
EACCESerror appears.
Why it matters
Permission errors block dependency installation entirely. They often appear after switching CI runners, changing Docker base images, or when teams mix sudo and non‑sudo workflows.
Prevention
- Standardize on a non‑root user for CI jobs.
- Clean
node_modulesbetween runs in CI to avoid leftover root‑owned files. - Use Docker images that define a non‑root default user (e.g.,
node:20).
Try it locally
ls -la node_modules
whoami
ls -la node_modules
How Faultline detects it
Use faultline explain npm-eacces-permission-denied to see the full playbook.
faultline analyze build.log
faultline explain npm-eacces-permission-denied
Generated from playbooks/bundled/log/build/npm-eacces-permission-denied.yaml. Do not edit directly.