Environment variables Railway error

Hello, I have a problem with environment variables within Railway. 11 days ago, my Next.js app was working correctly, but recently I deployed again and it failed. So, I added a Dockerfile, and the deploy worked. However, now the environment variables are not working. What am I missing? The enviroment variables are "NEXT_PUBLIC_BASE_URL" Attached the DockerFile Publish in my docker local and works correctly
No description
Solution:
1. the ARG lines are commented out 2. these variables are needed during building of the next app, therefore you need to reference them in the same image layer that is responsible for building...
Jump to solution
13 Replies
Percy
Percy10mo ago
Project ID: a2d0a173-be4f-421a-b1b0-ada4f0b76aa2
maldonadomoss
maldonadomossOP10mo ago
a2d0a173-be4f-421a-b1b0-ada4f0b76aa2
Brody
Brody10mo ago
your dockerfile is missing the reference to NEXT_PUBLIC_BASE_URL and whatever other variables you may need, please read this https://docs.railway.app/guides/dockerfiles#using-variables-at-build-time
maldonadomoss
maldonadomossOP10mo ago
it didnt work Add to dockerFile ARG NEXT_PUBLIC_BASE_URL RUN echo $NEXT_PUBLIC_BASE_URL command run echo if see it value in build Logs Railway
Brody
Brody10mo ago
show me the dockerfile you have now please please enclose that in a code block please enclose that in a code block
Brody
Brody10mo ago
that works too
Solution
Brody
Brody10mo ago
1. the ARG lines are commented out 2. these variables are needed during building of the next app, therefore you need to reference them in the same image layer that is responsible for building
maldonadomoss
maldonadomossOP10mo ago
If the variable line 36 is present, (NEXT_PUBLIC_BASE_URL) The commented variables are only for testing
Brody
Brody10mo ago
okay that solves 1. please read 2.
maldonadomoss
maldonadomossOP10mo ago
Thanks Its working
Brody
Brody10mo ago
awesome
Duchess
Duchess7mo ago
New reply sent from Help Station thread:
what should i do about to fix it here, i have the same problem, the variables are not detected by railway:
FROM node:18-alpine3.16




# Create app directory
WORKDIR /app

# Install app dependencies
COPY package.json ./
COPY tsconfig.json ./

# Bundle app source
COPY . .



RUN npm install -g @nestjs/cli
RUN npm install --omit=dev


# railway env variables
ARG RAILWAY_PUBLIC_DOMAIN
ARG RAILWAY_PRIVATE_DOMAIN
ARG RAILWAY_PROJECT_NAME
ARG RAILWAY_ENVIRONMENT_NAME
ARG RAILWAY_SERVICE_NAME
ARG RAILWAY_PROJECT_ID
ARG RAILWAY_ENVIRONMENT_ID
ARG RAILWAY_SERVICE_ID
# app env variables
ARG DATABASE_URL
ARG JWT_SECRET
ARG JWT_EXPIRES_IN

ENV DATABASE_URL=$DATABASE_URL \
JWT_SECRET=$JWT_SECRET \
JWT_EXPIRES_IN=$JWT_EXPIRES_IN \
RAILWAY_PUBLIC_DOMAIN=$RAILWAY_PUBLIC_DOMAIN \
RAILWAY_PRIVATE_DOMAIN=$RAILWAY_PRIVATE_DOMAIN \
RAILWAY_PROJECT_NAME=$RAILWAY_PROJECT_NAME \
RAILWAY_ENVIRONMENT_NAME=$RAILWAY_ENVIRONMENT_NAME \
RAILWAY_SERVICE_NAME=$RAILWAY_SERVICE_NAME \
RAILWAY_PROJECT_ID=$RAILWAY_PROJECT_ID \
RAILWAY_ENVIRONMENT_ID=$RAILWAY_ENVIRONMENT_ID \
RAILWAY_SERVICE_ID=$RAILWAY_SERVICE_ID


RUN npm run build


ENV NODE_ENV=production
EXPOSE 3000


CMD ["npm", "run", "start:prod"]
FROM node:18-alpine3.16




# Create app directory
WORKDIR /app

# Install app dependencies
COPY package.json ./
COPY tsconfig.json ./

# Bundle app source
COPY . .



RUN npm install -g @nestjs/cli
RUN npm install --omit=dev


# railway env variables
ARG RAILWAY_PUBLIC_DOMAIN
ARG RAILWAY_PRIVATE_DOMAIN
ARG RAILWAY_PROJECT_NAME
ARG RAILWAY_ENVIRONMENT_NAME
ARG RAILWAY_SERVICE_NAME
ARG RAILWAY_PROJECT_ID
ARG RAILWAY_ENVIRONMENT_ID
ARG RAILWAY_SERVICE_ID
# app env variables
ARG DATABASE_URL
ARG JWT_SECRET
ARG JWT_EXPIRES_IN

ENV DATABASE_URL=$DATABASE_URL \
JWT_SECRET=$JWT_SECRET \
JWT_EXPIRES_IN=$JWT_EXPIRES_IN \
RAILWAY_PUBLIC_DOMAIN=$RAILWAY_PUBLIC_DOMAIN \
RAILWAY_PRIVATE_DOMAIN=$RAILWAY_PRIVATE_DOMAIN \
RAILWAY_PROJECT_NAME=$RAILWAY_PROJECT_NAME \
RAILWAY_ENVIRONMENT_NAME=$RAILWAY_ENVIRONMENT_NAME \
RAILWAY_SERVICE_NAME=$RAILWAY_SERVICE_NAME \
RAILWAY_PROJECT_ID=$RAILWAY_PROJECT_ID \
RAILWAY_ENVIRONMENT_ID=$RAILWAY_ENVIRONMENT_ID \
RAILWAY_SERVICE_ID=$RAILWAY_SERVICE_ID


RUN npm run build


ENV NODE_ENV=production
EXPOSE 3000


CMD ["npm", "run", "start:prod"]
You're seeing this because this thread has been automatically linked to the Help Station thread.
Want results from more Discord servers?
Add your server