bun + turborepo monorepo application failing to respond
For some reason my application is saying it's failing to respond, however it successfully deploys (or at least it says so...)
I have
PORT
configured for Railway's default to be injected, so that isn't the issue. I also setup both my start & build scripts, which are:
Start: bun start --filter=api
Build: bun run build --filter=api
75 Replies
Project ID:
aac0388c-812d-41d2-abad-f664d8a4fc9f
aac0388c-812d-41d2-abad-f664d8a4fc9f
make sure you are listening on the $PORT environment variable
seem to be getting this now, weird
there is no HOST variable, just use
0.0.0.0
I have it set to (where these are under the env cost)
Sorry, it shouldn't been:
what is PORT set to in zod ?
you should use process.env.PORT instead, and if that isn't available then you can default to 8080, not sure what that looks like in zod though
will try rn
but i doubt thats the issue since it should be defined
is it? do you have a PORT service variable?
you'd still want to be listening on the PORT environment variable in code though
running into this issue now
when i try to deploy those new changes (but anything really)
keeps retrying
would you happen to have a custom start command set now?
the structure of my codebase is:
do you have the new builder also enabled? the new builder has a bug where it doesn't pass in the start command correctly
nope i dont
misread my bad
hmmm well those logs are not helpful, bun never prints anything helpful it seems
I assume you can still run the same pair of build and start commands locally without issues?
yeah
it all works locally
same start & build commands
even if you deleted the project and did another clone?
on railway or git
on git, delete the project locally and clone it again
what version of bun do you use locally, and what version of bun is railway using for your project? it's always best to have the cloud platform running the same versions of stuff as you run locally
what version does railway use?
where can i check that?
temporarily change the start command to a command that prints the version of bun
alright
ok
used the railway cli
thank god i got a bit more context
are you on the v2 runtime?
yeah
also, I the API app not with bun?
wdym
node dist/index.js
got it up to this point now
still getting
Application failed to respondin the api package, my scripts are:
we are back to this, please make these changes
oh shoot
forgot to change that back
what's the port railway uses by default?
just curious
it's random, that's why your app needs to listen on the PORT environment variable
please make this change
doing that rn
alright
just tried with:
seems to keep using 8080 thought, so
PORT
must not be defined by railwaywtf
am i doing something wrong
ok so
apparently it works if i just manually add
PORT
to my env variables
thank youwhile that will work, and it's by far the simpler way this is not the recorded way
okay
so after a bit of debugging
it seems like dotenv just doesnt want to parse the env variable on railway
it works locally though, which is weird
dotenv parses .env files
yeah
railway does not create .env files
they inject the variables directly into the environment
wdym
how would
process.env
not work?
i understand this
but not thisI don't know how I could clarify further
well maybe i can explain what i mean
i have variables that i set on railway, like below:
and im accessing them through
process.env
but when i test it by console logging, like console.log(process.env.GOOGLE_CLIENT_ID ?? "some google client id")
, it doesn't work, and goes to the fallback of some google client id
your code is doing something to unset them
oh actually
i think the issue is that the env variables are located in the root directory
and not in apps/api
the environment variables are injected into the containers environment, they aren't scoped to any specific directory
in a production environment like railway you don't even need to call dotenv
this is my
src/utils/env.ts
:
I have it set in Railway
and in my
src/index.ts
, all I do is
console.log(env.DATABASE_URL)
and for some reason it doesn't return the value that I put in railway
and instead that fallback of default db url goes here
can zod even parse process.env
yes
haha don't say yes, if it could, it would work
have done it before + works locally
so you have something missconfigured
will try without using zod for it
doesn't seem to work with this either
the thing is it works fine locally so i can't repro it
Solution
something you are doing is un-setting them
try removing dotenv because as mentioned, you don't need to call it when on railway