17 days ago
Symptom:
Builds consistently hang forever at the exact same point in the build log — right after next build prints the ▲ Next.js 14.2.35 version banner, before "Creating an optimized production build..." ever appears. No error is logged; the build just goes silent until Railway's own timeout eventually marks it FAILED (observed at ~40 minutes with generic error "Failed to build an image. Please check the build logs for more details.").
Deployment IDs that hung/failed this way (cache enabled):
9b123edc-875a-4025-b4af-1b6dc72e70c1
7df75837-3f82-45ce-8e31-e69535af08c2
ff2a0c7d-d48e-4639-b834-3bdc2b4f51dc (eventually FAILED after ~40 min)
e5fcbdaf-d810-489b-bae1-51d5443c1608 (same hang, reproduced again after re-enabling cache)
Workaround found:
Setting NO_CACHE=1 on the service and redeploying gets the build past the stall point every time and completes successfully in ~5-7 minutes (deployment 08e867e0-8342-4dd3-b111-7418abcad134, SUCCESS). Removing NO_CACHE and redeploying with a genuinely unrelated code change reproduced the identical hang again (e5fcbdaf), so this isn't a one-off — it looks like the persistent BuildKit cache mount for this service (s/87c7d3a3-8719-4378-9474-2a3cac7a9725-.../next/cache, node_modules/.cache, etc.) is in a stuck/corrupted state that a normal cache-hit build can't get past.
Ruled out on our side: The exact same next.config.js (including an "unrecognized key" warning that also appears in every build, cache or no cache) is present in the last successful production deploy and builds cleanly both locally and in the no-cache Railway build — so this isn't a config issue, just a stuck cache.
Anyone got any thoughts ?
3 Replies
Status changed to Awaiting Railway Response Railway • 17 days ago
17 days ago
This thread has been opened as a bounty so the community can help solve it.
Status changed to Open Railway • 17 days ago
15 days ago
Hey — your A/B already proves this: cache-on hangs at the Next.js banner; NO_CACHE=1 succeeds in ~5–7 min; removing it reproduces the hang. That matches Railway’s documented build-layer cache, not a bad next.config.js.
What Railway documents
By default Railway caches build layers. To disable that for a service, set:
NO_CACHE=1on the service Variables and redeploy (Build Configuration → Disable build layer caching).
Docs also note cache hits are not guaranteed because the build fleet scales — cold vs warm is expected (Why isn’t my build using cache?). Your case is the other mode: a warm/stuck layer set that never progresses, which a no-cache build bypasses.
Practical recovery
- Keep
NO_CACHE=1long enough to ship (SUCCESS on08e867e0-…). - Optionally remove it later and watch one deploy. If the hang returns at the same banner line, put
NO_CACHE=1back — that variable is the documented lever; there is no separate “purge cache” control. - For speed + reliability long-term, docs suggest building the image in your own pipeline and deploying the image directly (same section).
- The unrecognized-key warning in
next.config.jsappearing in both cache and no-cache builds is a red herring for the hang.
If it still stalls with NO_CACHE=1
Share full build logs for a hanging (cache-on) deploy vs a successful no-cache one. The IDs you listed already show the pattern.
Supported, documented fix for a stuck layer cache: NO_CACHE=1.
15 days ago
Your A/B test is strong enough to isolate this to Railway’s build-cache path rather than the Next.js application itself. Railway officially documents NO_CACHE=1 as the switch that disables build-layer caching, and your result is repeatable in both directions: cached builds hang at the same point, while NO_CACHE=1 builds complete in 5–7 minutes. The unrelated source change reproducing the hang after cache was re-enabled also makes a source/config regression much less likely. Railway’s Docker build documentation shows that cache mounts are service-specific, using IDs in the form s/-, which is consistent with one service retaining a bad cache while otherwise equivalent builds remain healthy. I would keep NO_CACHE=1 enabled as the production workaround for now rather than repeatedly burning 40-minute build attempts. Since Railway does not currently document a user-facing command for purging Railpack’s persistent build-layer cache for a single service, the useful next step for Railway staff is to invalidate/recreate the cache associated with service 87c7d3a3-8719-4378-9474-2a3cac7a9725. I’d also attach the full log from one cached failure and the successful NO_CACHE deployment, as requested above, so they can compare the generated build plan and cache-mount setup. If Railway resets that service cache and the next cached build succeeds, that would directly confirm the diagnosis. If it still hangs after a fresh service cache, then the next useful isolation would be the individual cache targets such as .next/cache versus node_modules/.cache rather than changing application code.