The ENOENT cache error occurs when npm's cache directory is missing or inaccessible. Clearing and rebuilding the cache usually resolves this issue.
npm maintains a cache of downloaded packages to speed up future installations. When the cache directory or specific cached files are missing or corrupted, npm may fail with ENOENT errors during cache operations. This can happen after system cleanups, disk errors, or when cache paths are misconfigured.
Check cache configuration:
npm config get cache
# Check if directory exists
ls -la $(npm config get cache)Clear and rebuild:
npm cache clean --force
# Verify cache
npm cache verifySet to default or new location:
# Reset to default
npm config delete cache
# Or set new location
npm config set cache /path/to/new/cacheEnsure proper access:
# Check permissions
ls -la ~/.npm
# Fix if needed
sudo chown -R $(whoami) ~/.npm
chmod -R u+rwX ~/.npmnpm's cache is content-addressable, making it safe to delete entirely. The cache grows unbounded - periodic npm cache clean may be needed. In CI, cache warming speeds up builds but stale caches can cause issues. Multi-user systems should have separate caches or use npm's --cache flag per-user. Docker builds benefit from caching the npm cache directory.
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
Manually create if missing:
mkdir -p ~/.npm/_cacache
mkdir -p ~/.npm/_logsEnsure cache persistence:
# Docker volume
volumes:
- npm-cache:/root/.npm
# GitHub Actions
- uses: actions/cache@v3
with:
path: ~/.npm
key: npm-cache-\${{ hashFiles('**/package-lock.json') }}