a month ago
I have a monorepo stup using bun. I am having issues deploying it using railway. Here is my current folder structure:
.
└── repo/
├── apps/
│ ├── api/
│ │ └── package.json (B)
│ ├── ui/
│ │ └── package.json (C)
│ ├── db/
│ │ └── package.json (D)
│ └── app/
│ └── package.json (E)
├── packages/
│ └── contracts/
│ └── package.json (F)
└── package.json (A)I keep getting this error
╭────────────────╮
Railpack 0.9.2
╰────────────────╯
↳ Detected Node
↳ Using bun package manager
↳ Found workspace with 5 packages
No start command was found.
To configure your start command, Railpack will check:
1. A "start" script in your package.json:
"scripts": {
"start": "node index.js"
}
2. A "main" field in your package.json pointing to your entry file:
"main": "src/server.js"
3. An index.js or index.ts file in your project root
If you have a static site, you can set the RAILPACK_SPA_OUTPUT_DIR environment variable containing the directory of your built static files.I currently have the following in Watch Paths
/apps/api/**
/apps/ui/**
Root Directory is set to /
Do i need a custom railway.json for api and ui?
I only want to deploy the ui and api and then do a migration to a database in railway
2 Replies
you might need a custom railway.json.
This tool might help with making one: https://railpack.crisog.com
https://docs.railway.com/guides/monorepo#automatic-import-for-javascript-monorepos
mentions that it will automatically detect the services in the monorepo, but i only see 1 service which is the monorepo, it's not splitting each service separately.
yes, therefore, you might need a custom railway.json.
a month ago
If you set up a public repo with an minimal example setup, I can help debugging this issue
does not answer my question. Do i need a seperate railway.json for each? where do i put it under each package? if so then the monorepo will not be able to install packages that are dependent from other packages
https://github.com/Salam81/railway-test
here is a minimal repo
a month ago
Hi.
You need to create two services. Set the root directory of one to apps/ui, and the other to apps/api. Make sure you correctly configure the endpoints. This should not and I believe cannot be done with one service.
a month ago
Alright. I'm going to send in a PR.
For one service, your API, you'll set the root directory to be nothing. Set the start command to be bun start:api.
For your UI, set the root directory to be apps/ui. The rest should be automatic for that.
Beautiful, the api seems to be working, but the UI still returns the same error
bun install --frozen-lockfile
bun install v1.3.1 (89fa0f34)
Resolving dependencies
Resolved, downloaded and extracted [172]
error: Workspace dependency "@Railway#2379-test/contracts" not found
Searched in "./*"
Workspace documentation: https://bun.com/docs/install/workspaces
error: elysia@catalog: failed to resolve
error: @elysiajs/eden@catalog: failed to resolve
error: @Railway#2379-test/contracts@workspace:* failed to resolvea month ago
Hmm. I didn't see usage of those APIs, but I guess they're needed. Going to look again, brb.
They're under the "@railway-test/contracts": "workspace:*" package, elysia is used in the catalog
a month ago
Almost there…
a month ago
Here we go.
Set your UI service back to no root directory.
Scroll to "Custom Build Command" and set it to cd apps/ui && bun vite build
Add a variable called RAILPACK_SPA_OUTPUT_DIR and set it to apps/ui/dist
a month ago
@P1NKPR0 ^^
a month ago
:D

a month ago
I'm also going to submit a PR that allows you to connect these two services. Right now you're just looking on localhost.
a month ago
Huzzah.
Status changed to Solved samgordon • about 1 month ago
@Sam any idea how i can acheive this or if i even should?
a month ago
Are you referring to a specific part of that? There's a lot there
a month ago
I can help you implement a Dockerfile which I believe will do all of the compilation in one shot, and won't require much of any setup at all.
a month ago
But smaller size doesn't matter on Railway, and I can't imagine the memory usage will differ that much either
i currently have this build script under apps/api
"build": "NODE_ENV=production bun build --compile --minify --target=bun-linux-x64 --outfile dist/server ./src/index.ts"
which builds a single executable, how can i make the railway service run that executable
a month ago
You'll need to change three things:
Your build command (in Railway):
bun --filter @railway-test/api buildYour start command (in Railway):
./apps/api/dist/server.
a month ago
I'll try that on my fork
a month ago
Oh shoot, this is not for the UI
a month ago
Editing
a month ago
Latest edit above is working for me ^^
