a year ago
Hey Railway team 👋
I have a front-end-only Next.js 14 app deployed to Railway. The deployment completes successfully, but shortly after, it crashes repeatedly with the following error:
Error: "next start" does not work with "output: export" configuration. Use "npx serve@latest out" instead.
Context:
- App is static only (no backend)
output: 'export'is set innext.config.js- Using
[email protected] - Docker-based deployment on Railway
- Current
startscript:"start": "next start -p $PORT"
Logs:
▲ Next.js 14.2.30 ✓ Starting... Error: "next start" does not work with "output: export" configuration. Use "npx serve@latest out" instead.
What I believe is happening:
- Since I’m using static export (
output: 'export'),next buildis generating anout/directory. - But my Dockerfile or
package.jsonis usingnext start, which only works with server-rendered apps.
Question:
What’s the best way to configure a static-only Next.js app with output: export to run properly on Railway?
Do I need to:
- Replace
next startwithserve out? - Adjust my Dockerfile accordingly?
- Switch to the Railway Static project type instead of a container?
Any advice or examples would be appreciated!
Thanks
2 Replies
a year ago
You should be able to deploy a static site with railpack
a month ago
AI-assisted; reproduced the reported error and tested the fix with synthetic pages.
For your Docker deployment, keep output: 'export' and next build, but replace the Docker runtime's next start with a static server for the complete out directory. You can keep the same Railway service.
Here is a complete two-stage Dockerfile, pinned static-server dependency/lockfile and reproduction. The build stage exports the app; the nonroot runtime installs only [email protected] and copies out. Its entrypoint is:
CMD ["node", "node_modules/serve/build/main.js", "out", "--config", "../serve.json", "--no-clipboard", "--no-port-switching"]serve reads Railway's runtime PORT directly. The root serve.json contains:
{"cleanUrls": true, "directoryListing": false}The config path is relative to out, hence ../serve.json. Avoid serve -s: its SPA fallback can hide missing routes behind a 200 home page.
Remove any Railway Custom Start Command still calling next start, so the image's CMD runs, and keep the public domain's target port aligned with the listening port. Railway documents this override.
Verification: 13 local checks passed; Linux CI also built and ran the actual Docker image, checking /, direct /about, custom 404, missing assets, nonroot execution and absence of the Next server. No Railway/requester deployment was tested.
The fixture pins 14.2.30 only to reproduce your historical report; use supported, patched Next dependencies in your real app. Does this resolve the Docker startup/routing issue?