Bun Monorepo support

Anonymous
FREE

9 days 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

Solved$20 Bounty

2 Replies

tsurg
HOBBY

9 days ago

you might need a custom railway.json.
This tool might help with making one: https://railpack.crisog.com


Anonymous
FREE

9 days ago

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.


tsurg
HOBBY

9 days ago


If you set up a public repo with an minimal example setup, I can help debugging this issue


Anonymous
FREE

9 days ago

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


Anonymous
FREE

9 days ago

I'll set one up shortly, thank you


tsurg
HOBBY

9 days ago

the railway.json file should be in the root of the repository.


Anonymous
FREE

8 days 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.


Anonymous
FREE

8 days ago

Doing so does not include the workspace dependencies.

1433225928569389000


Mph. Okay.

Can you share your root package.json file?



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.


Anonymous
FREE

8 days ago

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 resolve

Hmm. I didn't see usage of those APIs, but I guess they're needed. Going to look again, brb.


Anonymous
FREE

8 days ago

They're under the
"@railway-test/contracts": "workspace:*" package, elysia is used in the catalog


Almost there…


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


@P1NKPR0 ^^


:D

1433240558293225700


I'm also going to submit a PR that allows you to connect these two services. Right now you're just looking on localhost.


Anonymous
FREE

8 days ago

checking it now


Anonymous
FREE

8 days ago

You're a legend! thank you


Huzzah.


Status changed to Solved samgordon 8 days ago


Anonymous
FREE

8 days ago

@Sam any idea how i can acheive this or if i even should?

https://elysiajs.com/patterns/deploy.html


Are you referring to a specific part of that? There's a lot there


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.


But smaller size doesn't matter on Railway, and I can't imagine the memory usage will differ that much either


Anonymous
FREE

8 days ago

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


You'll need to change three things:

  • Your build command (in Railway): bun --filter @railway-test/api build

  • Your start command (in Railway): ./apps/api/dist/server.


I'll try that on my fork


Oh shoot, this is not for the UI


Editing


Latest edit above is working for me ^^


Anonymous
FREE

8 days ago

Works, thank you


Loading...