How to fix npm ERR! code EFAULT npm ERR! EFAULT: bad address in npm
EFAULT occurs when npm or Node.js encounters an invalid memory address or filesystem issues during package operations. This typically indicates filesystem corruption, permission issues, or memory constraints.
Quick fix
Fixes EFAULT
npm cache clean --force
rm -rf node_modules
rm package-lock.json
npm install- Clear npm cache and remove node_modules
- Check disk space and filesystem health
- Increase Node.js heap memory allocation
- Verify file system permissions and tmp directory
npm cache clean --forcerm -rf node_modulesrm package-lock.jsonnpm installnpm ERR! code EFAULTnpm ERR! EFAULT: bad address
What this error means
The EFAULT (bad address) error is a low-level system call failure that occurs when npm or Node.js attempts an operation with an invalid memory address or encounters filesystem issues during package operations. This typically happens during critical npm operations like mkdir, copyfile, or other system calls that interact with the file system. The error indicates that the operating system rejected the request because the memory address provided was invalid or inaccessible, often pointing to underlying filesystem corruption, permission issues, or environment-specific problems rather than a bug in npm itself.
Typical symptoms
- npm install command fails with 'EFAULT: bad address in system call argument' error
- Error occurs during file operations like mkdir or copyfile with specific paths like '/tmp/npm-XXXXX/...'
- npm commands work on some machines but fail on others with identical configurations
- Error appears when installing packages on Linux systems, Docker containers, or ARM-based systems
- The error happens intermittently or becomes reproducible only after certain dependency combinations
Common causes
- Corrupted npm or yarn cache storing invalid file references or metadata
- Insufficient memory (RAM or heap space) causing system calls to fail, especially in Docker containers
- File system corruption or issues with the partition/drive where node_modules or /tmp is located
- Attempting to copy or link files across different filesystems or mount points
- Environment-specific issues in non-standard Linux environments (GNURoot on Android, WSL, containers)
- Permission issues preventing npm from writing to the tmp directory or node_modules
How to fix "npm ERR! code EFAULT npm ERR! EFAULT: bad address"
Start with a complete clean slate by removing corrupted cache and dependencies:
npm cache clean --force
rm -rf node_modules
rm package-lock.json
npm installThe --force flag is required because npm refuses to clear the cache without it.
Verify that your filesystem has sufficient space and is healthy:
# Check available disk space
df -h
# Check for filesystem errors (Linux)
sudo fsck /dev/sdXY # replace with your partition
# On macOS, use Disk Utility or:
diskutil verifyVolume /Ensure the partition has at least 500MB free space. Check that /tmp directory permissions are correct: ls -ld /tmp should show drwxrwxrwt.
If running on a resource-constrained system, increase the memory available to Node.js:
# For npm 7+
NODE_OPTIONS="--max-old-space-size=4096" npm install
# For npm 6 and earlier
node --max-old-space-size=4096 /usr/local/bin/npm install
# For Docker, ensure adequate memory
docker run -m 4g your-image # allocate 4GB to containerEnsure npm can write to required directories:
# Check tmp directory permissions
ls -ld /tmp
# Should show: drwxrwxrwt
# If incorrect, fix permissions
sudo chmod 1777 /tmp
# Check npm cache directory permissions
chmod -R u+w ~/.npmSome versions of npm have known issues with file operations. Update to the latest stable versions:
# Check current versions
node --version
npm --version
# Update npm to latest
npm install -g npm@latest
# Update Node.js using nvm
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
nvm install 20
nvm use 20If the error persists, identify which package is causing the issue:
# Install packages individually to find the culprit
npm install package-name-1
npm install package-name-2
# Continue until error occurs
# Once identified, try a different version
npm install package-name@^1.5.0
# For cross-filesystem issues, verify the cache location
npm config get cache
# If it's on a different mount, consider changing it
npm config set cache /path/to/local/cacheAdvanced notes
The EFAULT error at the system call level is particularly common in virtualized or containerized environments (Docker, WSL, Raspberry Pi) where system call support may be limited or memory is constrained. If running in Docker, ensure the container has at least 2GB of memory. For cross-volume operations, consider reconfiguring npm's cache directory to be on the same filesystem as your project. On Linux systems with SELinux or AppArmor enabled, verify that npm/node processes aren't being blocked by security policies. The error can also occur if the system's file descriptor limit is too low—check with ulimit -n and increase if needed.
Frequently asked questions
- What does "EFAULT" mean?
- js attempts an operation with an invalid memory address or encounters filesystem issues during package operations. This typically happens during critical npm operations like mkdir, copyfile, or other system calls that interact with the file system. The error indicates that the operating system rejected the request because the memory address provided was invalid or inaccessible, often pointing to underlying filesystem corruption, permission issues, or environment-specific problems rather than a bug in npm itself.
- How do I fix "EFAULT"?
- EFAULT occurs when npm or Node.js encounters an invalid memory address or filesystem issues during package operations. This typically indicates filesystem corruption, permission issues, or memory constraints.
- What causes "EFAULT"?
- Corrupted npm or yarn cache storing invalid file references or metadata Insufficient memory (RAM or heap space) causing system calls to fail, especially in Docker containers File system corruption or issues with the partition/drive where node_modules or /tmp is located
- Is the "EFAULT" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- 📚npm Official Documentation
- 📖Docs: EFAULT Error(Official Docs)
- 💬SO: EFAULT error solutions(Stack Overflow)
- 🐙GitHub: npm issues(GitHub)