Env variable deploy react app

cesarsouza13HOBBY

a year ago

I deployed my back end application in springboot and created variables in the deploy instance to represent the environment and normally worked variables. When deploying my react application, the same thing did not happen, I created the environment variable correctly in the deploy instance and the code simply did not regulate the variable even though the names were aligned. Is there a different treatment for variables created in the deploy instance for a react application?

Solved

11 Replies

a year ago

please read this docs page for create-react-app https://create-react-app.dev/docs/adding-custom-environment-variables/

tl;dr variables on the frontend service must begin with REACT_APP_


cesarsouza13HOBBY

a year ago

I understand, I was already following these guidelines mainly regarding the REACTAPP prefix, even so it still seems that it is not recognizing the environment variable created in the variables session, to access the variables created in railway the code still uses process.env.REACTAPP .. . ?


a year ago

correct, but make sure to read the docs page I linked.


gmarcg00HOBBY

9 months ago

Same happens to me, any solution??


9 months ago

Please read the docs page I linked in the first message.


gmarcg00HOBBY

9 months ago

As the previous mate told you, we have followed the instructions in the document and the problem persists. If you do not know the solution, no problem, but do not refer us to a document which several people have read and it has not solved their problem


9 months ago

Dockerfile or Nixpacks?


gmarcg00HOBBY

9 months ago

Dockerfile



brody

Please read this docs section - https://docs.railway.app/guides/dockerfiles#using-variables-at-build-time

danielharagaoHOBBY

3 months ago

This finally resolved!!

You need to add 2 lines to the dockerfile to create the env variables on the right moment.

Using Variables at Build Time

If you need to use the environment variables that Railway injects at build time, which include variables that you define and Railway-provided variables, you must specify them in the Dockerfile using the ARG command.

For example:

# Specify the variable you need
ARG RAILWAY_SERVICE_NAME
# Use the varible
RUN echo $RAILWAY_SERVICE_NAME

Be sure to declare your environment variables in the stage they are required in:

FROM node

ARG RAILWAY_ENVIRONMENT

3 months ago

Yep that's what the docs say!


Status changed to Solved brody 3 months ago