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.
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.
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 offThe 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.
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files
How to fix 'npm ERR! code EMPTYPACKAGE' - Package contains no files
npm ERR! code EWORKSPACEMISSING npm ERR! Workspace does not exist: packages/missing
How to fix "npm ERR! code EWORKSPACEMISSING - Workspace does not exist" error
npm ERR! code EADDRNOTAVAIL npm ERR! errno EADDRNOTAVAIL npm ERR! Address not available
How to fix "npm ERR! code EADDRNOTAVAIL - Address not available" error