Running a Bun + pnpm Application on Railway
Hi!
I have a monorepo where I use pnpm + turborepo for repo & package managment. One of the apps in the repository, a discord bot, uses bun as its runtime, but still uses pnpm for the actual package installation. Any idea how I can go about getting this working w/ nixpacks / railway? Thanks!
Solution:Jump to solution
or just use 1.0.23 on railway, add
nixpkgsArchive = 'e99651a836b162b48fbf4195e0c8d3028b6b32a8'
below your [phases.setup]
54 Replies
Project ID:
bc172a5f-caaa-4872-a59d-62201654b4f6
bc172a5f-caaa-4872-a59d-62201654b4f6
I'd probably go about writing a custom nixpacks plan for that specific app where I would have a file like
bot.nixpacks.toml
with all the applicable configurations https://nixpacks.com/docs/configuration/file
and then the NIXPACKS_CONFIG_FILE
service variable set to name of my nixpacks file so that the custom build plan is only used for the bot servicesGot it, so would I want the nixpacks file to be at the root of the repo?
correct
Also, I am new to nixpacks config stuff. Does this seem like a good starting point?
Not really sure how my custom root for the service comes into play here
does any of the code in that folder access code outside of that folder? aka a shared monorepo
Yes, it accesses some shared packages in the
/packages/
directoryyeah looks decent, replace with the applicable bun build and start commands, also add an install phase with the applicable bun command
then setting the root directory to what you have would only copy in what's in that set directory meaning your bot code can't import something from directories elsewhere, it would need to be set to the root directory and that's where your custom
bot.nixpacks.toml
would liveGot it got it, have went ahead and done that, running into the following error during build:
I thought you wanted to use bun for the install, build, and start commands, looks like you're still using pnpm there.
for your install, build, and start commands in the custom build plan you would need to use commands that run in a set directory, so that for example your install command only installs the packages that the bot app requires
Yep, sorry for the miscommunication! I am only using bun for a runtime.
Currently I now have the service root set as just the root of the monorepo. Are you saying that
pnpm install
in the root would not work? On my local machine, pnpm handles monorepo stuffs so running pnpm install
at root installs for all packages & apps.okay only bun for runtime but pnpm for package management, got it!
yes pnpm install ran in the root will install all packages for all apps, but we only want to install the packages the bot needs, pnpm provides an applicable flag or argument of some sort to do such a thing but I don't know it off the top of my head
I can't find the command for chaining multiple packages / apps together in one command, but giving this a shot
why are you trying to run multiple installs, this is only the bot service
unless those are needed by the bot service?
The others are for dependent local packages in the monorepo,
bot
depends on config
and db
and I don't belive it cascades the install.noted
Yep 👍
then that looks like it would do the trick, sorry I'm having to do a lot of guess work here since I don't have much knowledge of shared monorepos and pnpm
Its all good! Very much apreciate the help :)
Still seems to be having trouble installing pnpm v 8.3.1? I found this thread and have updated my package.json to include the pnpm version but I think the issue is that npm 404s when trying to install it. https://www.answeroverflow.com/m/1131260702330462219
build fails with "ERR_PNPM_LOCKFILE_CONFIG_MISMATCH" - Railway
Pretty much what the title says.
Following the Nixpacks command order works both on my computer and a friend's (pnpm i --frozen-lockfile -> pnpm build -> pnpm start)
Full error:
```
#10 [stage-0 6/10] RUN --mount=type=cache,id=s/e15ed82c-c15e-4b05-b9dc-06a185373d18-/root/local/share/pnpm/store/v3,target=/root/.local/share/pnpm/store/v3 pnpm i ...
is npm having issues right now or something?
Dosen't look like it :/ https://status.npmjs.org/
Super odd issue, cause my understanding is that once a package is depended on you can't remove it right? So no real reason it should 404...
npm Status
Welcome to npm's home for real-time and historical data on system performance.
wait, that log screenshot says pnpm 8.31.1 but the latest version is 8.15.2?? https://github.com/pnpm/pnpm/releases
unless im missing something here?
no yeah that is really bizzare
do you have
8.31.1
set somewhere? and what is your local pnpm version?oh
I have it set as 8.3.1 in the app, but that at the root. Let me fix that and see if it works.
Looking good 👀
oh thats much progress!
Builds now working! Odd issue though where it just lists the scripts in the package.json instead of running the actual bot though...
what's with the mention of .env files?
Sort of a bun replacement for libraries like
dotenv
. That part is only used in dev, and it does not lead to any errors if the file does not exist and does not overwrite existing enviroment variables.okay cool, then that's very odd for sure
hey where you able to get the last leg of this issue sorted out?
Sadly I still haven't, have tried a few things but to no avail :/
it's always just printing out the available scripts?
Yep, only difference between my local environment and the railway one as far as I can tell is the version of bun (1.0.11 on railway vs 1.0.23 on local)
does bun even have an actual command to print available scripts?
Only think I have found is this which seems like the behaviour changed at some point https://github.com/oven-sh/bun/discussions/7585
GitHub
Script to output available scripts like
npm run
· oven-sh bun · D...I frequently used the old behavior of bun run with no arguments to see the available scripts in a project. Now that it includes the full help and examples every time it's not so useful. Here is...
Almost seems like bun run is not getting any arguments? That's really odd though as it definently is getting some.
show me again where and how you set your start command?
I do it via this nixpacks toml:
with the bot app
package.json
having the following scripts:
running pnpm run start --filter bot
from the root of the monorepo on my local machine leads to the bot starting correctlywhat does the build table say the start command is?
Where would the build table be at? This is what shows in settings for the service.
in the build logs
ah got it thx
thats not quite the command you showed me above?
sorry my bad had not copied the most recent version of the nixpacks toml
this is the deploy output
can you reproduce this behavior locally if you use bun 1.0.11?
Solution
or just use 1.0.23 on railway, add
nixpkgsArchive = 'e99651a836b162b48fbf4195e0c8d3028b6b32a8'
below your [phases.setup]
Setting the bun version worked!
Thank you!
Awesome, through I'm still curious, can you reproduce that behaviour with bun 1.0.11 locally?