Bun Monorepo support
Anonymous
PROOP

10 months 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

35 Replies

tsurg
FREE

10 months ago

you might need a custom railway.json.

This tool might help with making one: https://railpack.crisog.com


Anonymous
PROOP

10 months 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
FREE

10 months ago


10 months ago

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


Anonymous
PROOP

10 months 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
PROOP

10 months ago

I'll set one up shortly, thank you


tsurg
FREE

10 months ago

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


Anonymous
PROOP

10 months ago


10 months 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
PROOP

10 months ago

Doing so does not include the workspace dependencies.

1433225928569389098


10 months ago

Mph. Okay.

Can you share your root package.json file?



10 months 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.


Anonymous
PROOP

10 months 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

10 months ago

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


Anonymous
PROOP

10 months ago

They're under the

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


10 months ago

Almost there...


10 months 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


10 months ago

@P1NKPR0 ^^


10 months ago

:D

1433240558293225647


10 months 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.


Anonymous
PROOP

10 months ago

checking it now


Anonymous
PROOP

10 months ago

You're a legend! thank you


10 months ago

Huzzah.


Status changed to Solved samgordon 10 months ago


Anonymous
PROOP

10 months ago

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

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


10 months ago

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


10 months 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.


10 months ago

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


Anonymous
PROOP

10 months 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


10 months ago

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.

10 months ago

I'll try that on my fork


10 months ago

Oh shoot, this is not for the UI


10 months ago

Editing


10 months ago

Latest edit above is working for me ^^


Anonymous
PROOP

10 months ago

Works, thank you


Welcome!

Sign in to your Railway account to join the conversation.

Loading...