1 minute read

While working on a project, I used a Dockerfile to install dependencies and build an Angular 9 application. This post records an EXDEV error I encountered and the workaround I tried. Docker and npm behavior can vary by version and build setup, so treat this as a troubleshooting example rather than a universal fix.

What the npm EXDEV error means

The EXDEV error means an operation crossed a filesystem boundary. It is not specific to Docker, and the exact trigger depends on npm, the filesystem, and how the image layers are used. In my case, it appeared while changing npm-related files during a container build.

More specifically, this error can occur when npm tries to rename a file across filesystem boundaries. A rename is atomic only within the same filesystem, so crossing that boundary can produce EXDEV (cross-device link).

A workaround discussed in this npm issue was to move the directory before installing:

RUN mv ./node_modules ./node_modules.tmp \
  && mv ./node_modules.tmp ./node_modules \
  && npm install 

This was a workaround for the specific environment I encountered, not a general Docker fix. Container filesystems use layers, and rename behavior can differ across filesystems and mounts. Before adopting the workaround, reproduce the error with your current Node.js and npm versions and inspect which paths are on which filesystem. Prefer a supported install/build flow that produces dependencies in the same filesystem layer where they will be used.

Keep container builds reproducible

Containers are replaceable, so build-time dependencies should be reproducible from source and lockfiles. Generate required artifacts during the image build or include them in the build context. Pass secrets at runtime through an appropriate secret-management mechanism; don’t bake them into the image.

Updated: