6 days ago
stage-0
COPY . /app/.
195ms
stage-0
RUN npm ci && npm run build
2s
npm warn config production Use --omit=dev instead.
npm error code EBUSY
npm error syscall rmdir
npm error path /app/node_modules/.cache
npm error errno -16
npm error EBUSY: resource busy or locked, rmdir '/app/node_modules/.cache'
npm error A complete log of this run can be found in: /root/.npm/_logs/2025-10-23T22_02_48_724Z-debug-0.log
Dockerfile:30
-------------------
28 | # build phase
29 | COPY . /app/.
30 | >>> RUN --mount=type=cache,id=s/905e9ce5-0365-4749-8eeb-633b63129b4f-node_modules/cache,target=/app/node_modules/.cache npm ci && npm run build
31 |
32 |
-------------------
ERROR: failed to build: failed to solve: process "/bin/bash -ol pipefail -c npm ci && npm run build" did not complete successfully: exit code: 240
Error: Docker build failed
3 Replies
6 days ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
6 days ago
Can you try creating a .dockerignore file in the root of your project and add node_modules inside?
5 days ago
Hi there,
I ran into the same EBUSY error while testing and was able to track down the cause. Here’s what I found:
The issue appears to come from the Docker cache mount configuration. In my testing, I could reliably reproduce the error, and updating the cache mount target resolved it.
What failed:
---
RUN --mount=type=cache,target=/app/node_modules/.cache \
npm ci && npm run build
---
What worked in my testing:
---
RUN --mount=type=cache,target=/root/.npm \
npm ci --prefer-offline
COPY . .
RUN npm run build
---
I tested this on Railway and the build succeeded in with caching still working. Would you be able to try this and let me know if it works for you?
Why I think this Is Happening:
From what I can tell, the EBUSY: resource busy or locked error happens because Docker’s cache mount conflicts with npm’s file operations.
1. Docker locks the cache directory when using --mount=type=cache,target=/app/node_modules/.cache to keep it consistent across builds.
2. npm or your build tool: then tries to modify or clean that same directory during npm ci or the build process.
3. Result: npm can’t modify the locked folder, causing the EBUSY error.
It looks like the issue is caching a project-level cache directory that your build tools need to manage, rather than npm's own package cache. If it would be helpful, I can share my very basic setup here.
Feel free to let me know if I'm missing anything 