2 months ago
Hello, I was wondering if anyone had this issue as well:
I'm getting the error shown in the screenshot while deploying a docker image on railway.
<img width="523" alt="Image" src="https://github.com/user-attachments/assets/3aff1637-a9b6-463d-a8da-443532a51a86" />
What I've tried:
1. specifying these env vars in turbo.json
didn't help
2. turbo in loose mode didn't work
I've also posted the issue on t3-env issues (https://github.com/t3-oss/t3-env/issues/344; no responses yet) but the weird thing is that it doesn't happen on local, only when deploying to railway.
3 Replies
16 days ago
Anyone came up with a solution for this yet?
According to the Next.js docs, NEXT_PUBLIC_ variables are "inlined" into the JavaScript bundle at BUILD TIME, not runtime. This means:
1. You need the environment variable available in the builder stage of your Dockerfile where next build
happens
2. After the build, these values are frozen and won't respond to runtime changes
Yet this still doesn't work in my Dockerfile:
```
# In the builder stage where next build happens
FROM base AS builder
ARG RAILWAY_PUBLIC_DOMAIN # Get Railway's domain as build arg
# Set NEXT_PUBLIC_ var during build - this is when Next.js inlines it
ENV NEXT_PUBLIC_APP_URL=https://${RAILWAY_PUBLIC_DOMAIN}
# Then do your build
RUN pnpm build --filter=${PROJECT}
```
16 days ago
Hey! I saw your issue and wanted to help. This kind of problem usually comes from environment variables not being passed correctly during Railway’s Docker build/deploy process. Even if turbo.json or .env works locally, Railway won’t automatically use them unless you set them explicitly.
Here are a few things you can try:
Set env vars directly in Railway’s dashboard:
Go to your Railway project → Variables tab → add all the environment variables your app needs (even if they’re already in .env locally).If you use a Dockerfile, make sure build-time vars are handled:
ARG MY_VAR
ENV MY_VAR=$MY_VAR
Then in railway.json, you can pass them like this:
{
"build": {
"env": {
"MY_VAR": "your-value"
}
}
}
Check t3-env behavior:
t3-env can sometimes fail silently if the environment variables are missing or not loaded during build. Try logging a few key vars in production to confirm they’re loaded:
console.log(process.env.YOUR_VAR_NAME);
sthb851
Hey! I saw your issue and wanted to help. This kind of problem usually comes from environment variables not being passed correctly during Railway’s Docker build/deploy process. Even if turbo.json or .env works locally, Railway won’t automatically use them unless you set them explicitly.Here are a few things you can try:Set env vars directly in Railway’s dashboard:Go to your Railway project → Variables tab → add all the environment variables your app needs (even if they’re already in .env locally).If you use a Dockerfile, make sure build-time vars are handled:ARG MY_VARENV MY_VAR=$MY_VARThen in railway.json, you can pass them like this:{"build": {"env": {"MY_VAR": "your-value"}}}Check t3-env behavior:t3-env can sometimes fail silently if the environment variables are missing or not loaded during build. Try logging a few key vars in production to confirm they’re loaded:console.log(process.env.YOUR_VAR_NAME);
15 days ago
I was making 2 mistakes actually:
1. I tested multiple scenarios, and when I wrote my latest reply, I removed the thing you are talking about at point 2.
2. I was using a z.string().url() validation on the RAILWAY_PUBLIC_DOMAIN, which doesn't include the protocol scheme, so ofc it was failing
Status changed to Solved chandrika • 15 days ago