How to fix npm ERR! code EROFS npm ERR! EROFS: read-only file system in npm
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)'- Verify the actual file system status
- Configure npm to use a writable directory
- Check and fix ~/.npmrc configuration
- For containerized environments (Docker)
# Check if the npm cache directory is writabletouch ~/.npm/test-write.tmp && rm ~/.npm/test-write.tmp && echo 'Writable' || echo 'Read-only'# Check npm root and cache configurationnpm root -gnpm config list --json | grep -E '(prefix|cache)'npm ERR! code EROFSnpm 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
- 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
- AWS Lambda or serverless environment where /var/task is read-only; only /tmp is writable
- Dual-boot system where Windows fast-boot interference affects file system state on Linux partition
- 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"
Confirm whether the file system is truly read-only or if it's an npm configuration issue:
# 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)'Change npm's cache and prefix directories to a location that supports writes:
# 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 installYour .npmrc file may contain problematic settings:
# 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 ~/.localEnsure your Dockerfile sets up proper mount points and permissions:
# 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 installAlternatively, build with Docker BuildKit cache mounts:
docker build --mount=type=cache,target=/root/.npm .Lambda functions only have write access to the /tmp directory:
# In your build process or Lambda handler setup
export HOME=/tmp
npm config set cache '/tmp/npm-cache'// 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-onlyIf using shared folders in virtual machines, enable symlink support:
# 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/shareFor dual-boot systems, disable Windows fast-boot:
# In PowerShell as Admin
powercfg /h offAdvanced 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
- 📚npm Official Documentation
- 📖Docs: EROFS Error(Official Docs)
- 💬SO: EROFS read-only filesystem(Stack Overflow)
- 🐙GitHub: npm issues(GitHub)