Environment variables not injected

eliasknudsen
HOBBY

5 months ago

Hi. I am having issues loading environment variables into my react app. Shouldnt railway inject the env file before building from a docker file?

My projectid:
1c54023d-5b2e-4289-9c9d-ef70f16a2222

The name of the service that doesnt load the variables: openSignClient

This is the dockerfile:

# Use an official Node runtime as the base image
FROM node:18

# Set the working directory inside the container
WORKDIR /usr/src/app

# Copy package.json and package-lock.json first to leverage Docker cache
COPY ./package*.json ./

# Install application dependencies
RUN npm install

# Copy the current directory contents into the container
COPY ./ .
COPY ./.husky .

RUN npm run build

# Make port 3000 available to the world outside this container
EXPOSE 3000

# Define environment variables if needed
# ENV NODE_ENV production

# Run the application
ENTRYPOINT npm run start

This is the package json from the service:

"scripts": { "build": "npm run version && react-scripts build", "start-dev": "react-scripts start", "start": "serve -s build -l 3000",

The environment variables start with "REACT_APP" so i know that this isnt the issue.

Solved

0 Replies

5 months ago

Hello,

I think this docs page will be helpful -


eliasknudsen
HOBBY

5 months ago

ok nice, but do i need to add every single one by line? Isnt there a way to add the whole railway environment at build? I dont want to manage the variables in multiple places.


5 months ago

you only need to add the variables that your build process consumes during build, either way you do need to manually define the variables that you need during build, runtime is handled automatically.

Or switch to Railpack since Railpack handles that all for you.


5 months ago

!s


Status changed to Solved brody 5 months ago


Environment variables not injected - Railway Help Station