5 months ago
How do I go about doing this?
Can't find a good example and need to be pointed in the right direction.
Folder structure is:
app/
frontend/
src/
main.tsx
index.html
package.json
server/
index.ts
package.json (of the server)
tesconfig.json (of the server
5 Replies
5 months ago
Create two services from the same repo and set the root directory to frontend/ for one and server/ for the other in each service's settings. Our monorepo deployment guide covers the full setup including watch paths to prevent unnecessary rebuilds.
Status changed to Awaiting User Response Railway • 5 months ago
sam-a
Create two services from the same repo and set the root directory to `frontend/` for one and `server/` for the other in each service's settings. Our [monorepo deployment guide](https://docs.railway.com/guides/monorepo) covers the full setup including watch paths to prevent unnecessary rebuilds.
5 months ago
Hi sam, yes this is the current setup.The run script for my server is in the root. That builds fine. This issue is with the frontend where I get an error of:
vite v7.3.1 building client environment for production...
transforming...
✓ 1966 modules transformed.
✗ Build failed in 2.03s
error during build:
undefined
error: script "build" exited with code 1
ERROR: failed to build: failed to solve: process "sh -c bun run build" did not complete successfully: exit code: 1
I have set it to frontend and fixed the build command to be the correct bun run build, but no luck.
Status changed to Awaiting Railway Response Railway • 5 months ago
5 months ago
The "undefined" error during Vite build is typically a configuration issue in your project. Railpack needs a bun.lock file present in the frontend/ directory to properly detect Bun as the package manager - without it, the build may not install dependencies correctly.
BTW, this is application-level build configuration which falls outside our support scope (but thought I would try to help). If you're still stuck after checking the lockfile, let us know and we can route this to our community bounty program where someone can help debug your specific setup.
Status changed to Awaiting User Response Railway • 5 months ago
Status changed to Solved sam-a • 5 months ago
sam-a
The "undefined" error during Vite build is typically a configuration issue in your project. Railpack needs a `bun.lock` file present in the `frontend/` directory to properly detect Bun as the package manager - without it, the build may not install dependencies correctly. BTW, this is application-level build configuration which falls outside our support scope (but thought I would try to help). If you're still stuck after checking the lockfile, let us know and we can route this to our community bounty program where someone can help debug your specific setup.
5 months ago
Appreciate you going outside the scope. I checked - I do have a bun.lock file present in the frontend, tried to get my backend to then serve the static files after building the frontend as it could deploy. However, despite the build working none of the backend routes work on the url. How can I get some help from community?
Status changed to Awaiting Railway Response Railway • 5 months ago
a month ago
The clean Railway setup is usually two services from the same repo:
- Frontend service: root directory
frontend, buildbun install && bun run build, outputdist - Backend service: root directory
serverorapi, start with your Hono server
Then set the frontend’s API URL to the backend Railway domain, or use a public/custom domain for the API.
If you want one Railway service instead, the backend has to serve the built Vite files. Example flow:
bun install
cd frontend && bun install && bun run build
cd ../server && bun install && bun run start
Then in Hono, serve the frontend dist directory after your API routes, and make sure the server listens on Railway’s port:
const port = Number(process.env.PORT || 3000)
The common failure is deploying only the Hono server while the Vite app was built into a separate folder that the server never serves.