Replies: 3 comments 2 replies
This comment was marked as spam.
This comment was marked as spam.
-
|
For runtime configurations, this is our current setup:
We build in dotenvx run --env-file=.env.<dev|staging|prod> -- node server.jsThen, in the Of course this only works with SSR. Some optimizations can be made to only add the env to the page props on the first page load and skip it for navigation. |
Beta Was this translation helpful? Give feedback.
-
|
Regarding that It is a bit annoying but Node.js' printouts for fetch errors, can sometimes... end up being cryptic, like: > fetch("http://localhost:3000/abc")
Promise {
<pending>,
[Symbol(async_id_symbol)]: 454,
[Symbol(trigger_async_id_symbol)]: 434
}
> Uncaught [TypeError: fetch failed] {
[cause]: AggregateError [ECONNREFUSED]:
at internalConnectMultiple (node:net:1122:18)
at afterConnectMultiple (node:net:1689:7)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
code: 'ECONNREFUSED',
[errors]: [ [Error], [Error] ]
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
To begin with – I’m not a frontend developer, and I’ve never written a single line of code in Next.js. This time, I’m speaking from a DevOps perspective.
On a daily basis, I work with Kubernetes and/or Docker + Compose. And I must say – I’ve rarely had such a confusing experience when trying to deploy and operate a modern web framework as I’ve had with Next.js.
I’m sharing this not as a rant, but in hopes of sparking a productive discussion about how Next.js could be made more friendly for containerized, production-grade environments.
1. Runtime Configuration
In Node.js projects, configuration typically comes from
process.env, which works fine for server-side logic.However, frontend code in the browser doesn’t have access to those variables. Instead, you’re expected to expose them by prefixing with NEXT_PUBLIC_. The issue?
This effectively bakes environment variables into the build output, making runtime configuration nearly impossible.
Most modern CI/CD pipelines assume that you build an image once and reuse it across multiple environments by changing runtime variables. In Next.js, however, this isn’t really possible unless you rebuild the app for every environment – which defeats the purpose of immutable builds and slows deployments.
The alternative — building during deployment – is also not great, as production servers shouldn’t be doing CPU-intensive builds just to inject config.
Has anyone found a clean pattern or official recommendation from the Next.js team to handle this scenario? What I'm using currently is a solution found somewhere on Reddit with "BAKED_NEXT_PUBLIC_" vars that are replaced with
sedon runtime launch. This is not good.2. Having a Backend for Frontend
A production-built React SPA can easily run in an nginx container using ~32 MB of memory.
By contrast, a Next.js app (even for mostly static content) requires a full Node.js runtime, easily consuming 512 MB or more.
That might be fine for some use cases, but it feels like an architectural mismatch for simpler frontends — especially when the benefits of SSR or “server actions” aren’t strictly required. This tight coupling between backend and frontend layers makes operations heavier and removes flexibility. Caches like Varnish or even plain nginx reverse proxies allow for clearer separation of concerns – something that’s harder to achieve in Next.js (but maybe easier out-of-the-box).
So, is Next.js meant only for apps that truly need server-side rendering, or is there a recommended way to deploy it more like a traditional frontend app?
3. Logging
Logging should help you understand what went wrong – not just confirm that something did.
Here’s a real-world example I encountered recently:
What does
fetch failedeven mean here? Which URL failed? What context or request triggered this?The stack trace references deeply optimized internal code – none of which is helpful for diagnosing the issue.
I get that this is partly due to bundling and optimization, but perhaps there’s a way for Next.js to preserve clearer, source-mapped logs (especially for production server)?
Final Thoughts
I completely understand that Next.js is flexible and allows deep customization. Still, some sensible defaults for DevOps workflows – such as runtime configuration, lightweight deployments, and readable server logs – would make a huge difference.
This post may stem from my limited experience with Next.js, but I wanted to share the operational challenges I’ve faced and hear how others are handling them. Maybe I’m missing a better approach – and if so, I’d love to learn from you.
4 votes ·
Beta Was this translation helpful? Give feedback.
All reactions