Is Railway caching .next build output?

gaearon
FREE

10 days ago

Hi folks! I'm debugging an issue where Railway deploys of a Next.js seem to be caching code from node_modules.
More concretely:

  1. I apply a patch using patch-package to node_modules in postinstall and also prebuild (just in case)

  2. I see the patch being applied in the log

  3. However, the final build output in .next contains old code

This is driving me nuts!

With some help from Claude, I've managed to narrow it down so that putting rm -rf .next/server .next/static .next/*.json .next/BUILD_ID || true in prebuild fixes the issue . I'll try to narrow it down further because I'm not sure which part helps.

But is there a documented list of all possible caches somewhere? I've tried adding NO_CACHE=1 to variables to no avail.

I'm not sure why I need to post project ID (aren't projects private) but mine is da45634a-bfa6-4338-9079-dc256ab1b66b/service/1abd16e0-ecab-4825-b3cf-262c4eaaa337 (I think?)

Thanks!

$10 Bounty

0 Replies

gaearon
FREE

10 days ago

seems like this is the fix

"build": "rm -rf .next/cache/* && next build",

9 days ago

What builder are you using?


9 days ago

It looks like Railpack does in fact cache .next/cache.


9 days ago

And, as it happens, Nixpacks does too.


9 days ago

So, to answer your question about docs, the answer would be that it'll be in the documentation of whichever build system you're using.


gaearon
FREE

9 days ago

I’m using the default one (Railpack). What I couldn’t find in the docs:

  • How to turn off this caching

  • What the exact cache keys are (I presume it’s fingerprinting the lockfile?)

Both of these are pretty critical to being able to resolve the issue. The “manually remove” approach I went with is a hack.


gaearon
FREE

9 days ago

Also, usually deploying services have a “delete caches” and “redeploy without cache” button. So that’s a feature request I guess. I’m not sure how one is supposed to solve these types of issues otherwise.


9 days ago

The cache key should actually just be next. As far as turning it off, I'm not sure that's implemented at the moment, short of what you're doing right now.


Loading...