How to fix npm ERR! code EROFS npm ERR! EROFS: read-only file system in npm

npmINTERMEDIATEHIGHUpdated Dec 5, 2025· 135 views

EROFS occurs when npm attempts to write files but the file system is read-only. This is common in containers, serverless functions, and virtualized environments. Configure npm to use a writable directory.

Quick fix

Fixes EROFS

# Check if the npm cache directory is writable
touch ~/.npm/test-write.tmp && rm ~/.npm/test-write.tmp && echo 'Writable' || echo 'Read-only'

# Check npm root and cache configuration
npm root -g
npm config list --json | grep -E '(prefix|cache)'
  1. Verify the actual file system status
  2. Configure npm to use a writable directory
  3. Check and fix ~/.npmrc configuration
  4. For containerized environments (Docker)
npm — error
# Check if the npm cache directory is writable
touch ~/.npm/test-write.tmp && rm ~/.npm/test-write.tmp && echo 'Writable' || echo 'Read-only'
# Check npm root and cache configuration
npm root -g
npm config list --json | grep -E '(prefix|cache)'
npm ERR! code EROFS
npm ERR! EROFS: read-only file system

What this error means

EROFS (Error Read-Only FileSystem) occurs when npm attempts to write files or create directories during package installation or script execution, but the underlying file system is read-only or doesn't support the operation. This is a file system-level restriction, not a permission issue with your user account. The error typically manifests when npm tries to create node_modules directories, write to the cache, or execute scripts that require temporary file creation. It's common in containerized environments, serverless functions, and virtualized systems.

Typical symptoms

  • npm install command fails with 'mkdir' or 'open' operation errors on specific paths
  • npm scripts fail to execute with EROFS errors when attempting to write temporary files
  • Installation works on one environment but fails in containerized or virtualized environments
  • AWS Lambda or serverless function deployments fail during npm operations
  • File system appears to have correct permissions but npm operations still cannot write files

Common causes

  1. File system is genuinely read-only due to mount options (common in containers, VMs, or cloud functions)
  2. npm cache directory is configured to a read-only location in ~/.npmrc
  3. Virtual machine shared folders (VirtualBox, VMware) don't support symlinks required by npm
  4. AWS Lambda or serverless environment where /var/task is read-only; only /tmp is writable
  5. Dual-boot system where Windows fast-boot interference affects file system state on Linux partition
  6. npm @npmcli/run-script writes to tmpdir which may be read-only in some sandboxed environments

How to fix "npm ERR! code EROFS npm ERR! EROFS: read-only file system"

1Verify the actual file system status

Confirm whether the file system is truly read-only or if it's an npm configuration issue:

bash
# Check if the npm cache directory is writable
touch ~/.npm/test-write.tmp && rm ~/.npm/test-write.tmp && echo 'Writable' || echo 'Read-only'

# Check npm root and cache configuration
npm root -g
npm config list --json | grep -E '(prefix|cache)'
2Configure npm to use a writable directory

Change npm's cache and prefix directories to a location that supports writes:

bash
# Set npm cache to /tmp (or another writable location)
npm config set cache '/tmp/npm-cache'

# Set npm prefix to a user-writable directory
npm config set prefix ~/.local

# Verify the changes
npm config list --json

# Clear npm cache and try install again
npm cache clean --force
npm install
3Check and fix ~/.npmrc configuration

Your .npmrc file may contain problematic settings:

bash
# Backup and view your current .npmrc
cp ~/.npmrc ~/.npmrc.backup
cat ~/.npmrc

# For a fresh start, move your old config
mv ~/.npmrc ~/.npmrc.old
npm config list --json

# Reconfigure as needed
npm config set prefix ~/.local
4For containerized environments (Docker)

Ensure your Dockerfile sets up proper mount points and permissions:

dockerfile
# Create writable directories in the container
RUN mkdir -p /tmp/npm-cache && chmod 777 /tmp/npm-cache

# Configure npm to use the writable cache
RUN npm config set cache '/tmp/npm-cache'

# Install dependencies
RUN npm install

Alternatively, build with Docker BuildKit cache mounts:

bash
docker build --mount=type=cache,target=/root/.npm .
5For AWS Lambda or serverless functions

Lambda functions only have write access to the /tmp directory:

bash
# In your build process or Lambda handler setup
export HOME=/tmp
npm config set cache '/tmp/npm-cache'
javascript
// In application code, write temporary files to /tmp only
const fs = require('fs');
// Correct: uses /tmp for temporary storage
fs.writeFileSync('/tmp/output.txt', data);
// NOT: /var/task is read-only
6For virtualized environments (VirtualBox, VMware)

If using shared folders in virtual machines, enable symlink support:

bash
# VirtualBox: enable symlinks on the host
VBoxManage setextradata VM_NAME VBoxInternal2/SharedFoldersEnableSymlinksCreate/share 1

# Then remount the shared folder
mount -t vboxsf -o remount,exec share /mnt/share

For dual-boot systems, disable Windows fast-boot:

powershell
# In PowerShell as Admin
powercfg /h off

Advanced notes

The EROFS error is distinct from permission errors (EACCES). It indicates the file system itself (via mount options, VM constraints, or cloud function sandboxing) prevents write operations, not user permissions. In serverless/FaaS environments, this is by design for security—only /tmp provides writable storage. Recent npm versions write @npmcli/run-script temporary files to the system tmpdir, which can trigger EROFS in read-only file systems; using npm --prefer-offline or npm ci with a pre-built node_modules can work around this.

Frequently asked questions

What does "EROFS" mean?
EROFS (Error Read-Only FileSystem) occurs when npm attempts to write files or create directories during package installation or script execution, but the underlying file system is read-only or doesn't support the operation. This is a file system-level restriction, not a permission issue with your user account. The error typically manifests when npm tries to create node_modules directories, write to the cache, or execute scripts that require temporary file creation.
How do I fix "EROFS"?
EROFS occurs when npm attempts to write files but the file system is read-only. This is common in containers, serverless functions, and virtualized environments. Configure npm to use a writable directory.
What causes "EROFS"?
File system is genuinely read-only due to mount options (common in containers, VMs, or cloud functions) npm cache directory is configured to a read-only location in ~/.npmrc Virtual machine shared folders (VirtualBox, VMware) don't support symlinks required by npm
Is the "EROFS" 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