8 months ago
👋 Hi team,
I'm trying to deploy a monorepo with front app and multiple microservices (pnpm workspaces), and it's been a really frustrating experience.
https://github.com/alex1yaremchuk/healthy-summer
after jumping through some hoops it even published something, but… LOCALLY..
Specifically:
Railway does not allow me to select a subdirectory for a given service
There's no way to set a working directory for build and start commands
Even when I specify everything manually (
PORT,preview --host, correct vite.config), Railway starts the process but does NOT expose any public URLYou expect a
startscript in the root, but that doesn't work for multi-service reposThis is a paid account, and it feels broken for any serious monorepo use
What I expect is simple: just let me choose a subdirectory (like packages/frontend) to build/deploy. That's it.
Please fix this. Or at least provide official support for monorepos without Docker or forcing me to split into 5 repos.
6 Replies
8 months ago
This is something you need to configure yourself. I have a monorepo with pnpm workspaces deployed on railway, the folder structure is something like this
apps/web - Tanstack start app
apps/api - Hono Api
packages/eslint-config
packages/types
packages/api-client
I also have a docker directory at the root of the project and have custom Dockerfiles for my apps
docker/web/Dockerfile
docker/api/Dockerfile
The Dockerfile is setup to build the individual application and pnpm automatically takes care of installing and building dependecies in order. This works for me but try something like turborepo or NX if you want more control.
I haven't faced any issues with railway so far. monorepos are complex and can vary, like you have all the apps in packages directory while the standard is to put it in apps dir or the root of the project
You shouldn't expect the hosting provider to take care of this for you. This is something you need to set it up yourself.
the way i manage this is by deploying the repo multiple times, each with a different Root Directory and Watch Paths setting corresponding to the right service
8 months ago
Looking at your repo more carefully, I see that no service depends on another
The problem comes from pnpm-lock.yaml file which is at the root of the repo, so when you set the root directory to be packages/frontend, it will only grabs the code from that path which doesn't have the pnpm-lock file
8 months ago
Here's something you can try, this is however theoretical and I am like 60% sure it would work. I use this to run dev environments locally.
Try setting all the production related commands like build and start in the root package.json as well.
Like,"build:frontend" : "pnpm run --filter frontend build""start:frontend" : "pnpm run --filter frontend start"
Then in your frontend define a build and start script, In your railway dashboard set the build and start script to be pnpm build:frontend and pnpm start:frontend
Also keep the root directory to / and not subpaths so it can access the files in root dir.
8 months ago
I just realized i looked at @skyaviatour's reply and assumed it was op replying to my comment.
7 months ago
Hey alex1yaremchuk, Did you try my solution ?
If it didn't work then let me know and I can fork the repo and set up every commands and open up a pull request.
