How to fix npm ERR! code EFAULT npm ERR! EFAULT: bad address in npm

npmINTERMEDIATEHIGHUpdated Dec 5, 2025· 115 views

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
  1. Clear npm cache and remove node_modules
  2. Check disk space and filesystem health
  3. Increase Node.js heap memory allocation
  4. Verify file system permissions and tmp directory
npm — error
npm cache clean --force
rm -rf node_modules
rm package-lock.json
npm install
npm ERR! code EFAULT
npm 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

  1. Corrupted npm or yarn cache storing invalid file references or metadata
  2. Insufficient memory (RAM or heap space) causing system calls to fail, especially in Docker containers
  3. File system corruption or issues with the partition/drive where node_modules or /tmp is located
  4. Attempting to copy or link files across different filesystems or mount points
  5. Environment-specific issues in non-standard Linux environments (GNURoot on Android, WSL, containers)
  6. 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"

1Clear npm cache and remove node_modules

Start with a complete clean slate by removing corrupted cache and dependencies:

bash
npm cache clean --force
rm -rf node_modules
rm package-lock.json
npm install

The --force flag is required because npm refuses to clear the cache without it.

2Check disk space and filesystem health

Verify that your filesystem has sufficient space and is healthy:

bash
# 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.

3Increase Node.js heap memory allocation

If running on a resource-constrained system, increase the memory available to Node.js:

bash
# 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 container
4Verify file system permissions and tmp directory

Ensure npm can write to required directories:

bash
# 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 ~/.npm
5Update Node.js and npm to latest versions

Some versions of npm have known issues with file operations. Update to the latest stable versions:

bash
# 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 20
6Isolate the problematic package

If the error persists, identify which package is causing the issue:

bash
# 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/cache

Advanced 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