Skip to content
Latchkey

npm "EROFS: read-only file system" - Fix Writes to a Read-Only Path in CI

EROFS means npm attempted to write to a path mounted read-only - a cache dir, node_modules, or a global prefix on a read-only layer. The fix is to redirect npm’s writes to a writable location.

What this error means

npm fails with EROFS: read-only file system for a path under the cache, prefix, or install dir. It is common in hardened containers, distroless/read-only root filesystems, or when installing into a read-only mounted volume.

npm output
npm error code EROFS
npm error syscall mkdir
npm error path /nonexistent/.npm
npm error errno -30
npm error Error: EROFS: read-only file system, mkdir '/usr/lib/node_modules/...'

Common causes

The npm cache or HOME points at a read-only path

A container with a read-only root filesystem leaves $HOME/~/.npm unwritable, so npm cannot create its cache directory.

Installing into a read-only mount

A global prefix or a project dir on a read-only volume cannot be written, so install or link operations hit EROFS.

How to fix it

Redirect npm writes to a writable dir

Set the cache and prefix to a writable, ephemeral location.

Terminal
export npm_config_cache=/tmp/.npm
export npm_config_prefix=/tmp/.npm-global
npm ci

Mount a writable working area

  1. Give the container a writable /tmp or a mounted volume for the workspace and cache.
  2. Ensure $HOME is writable, or override npm_config_cache.
  3. Install on a writable layer, not a read-only mount.

How to prevent it

  • Point npm cache/prefix at a writable path on read-only filesystems.
  • Install on writable layers, not read-only mounts.
  • Provide a writable HOME/tmp in hardened containers.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →