R
Railway8mo ago
bbot

Can't get React + Docker production running with ENV variables

Hello! I have a Create React app, attempting to load via Dockerfile. Works perfectly fine in dev with variables and using npm run dev For production, followed this common answer that didn't work I'm wondering if it's because I had to eject the app maybe? Not sure, but here is where I am now. This is my package.json:
"scripts": {
"start": "serve build -s -n -L -p $PORT",
"dev": "node scripts/start.js NODE_ENV=development",
"build": "GENERATE_SOURCEMAP=false node scripts/build.js",
"test": "node scripts/test.js"
}
"scripts": {
"start": "serve build -s -n -L -p $PORT",
"dev": "node scripts/start.js NODE_ENV=development",
"build": "GENERATE_SOURCEMAP=false node scripts/build.js",
"test": "node scripts/test.js"
}
This is my Dockerfile:
# Base image
FROM node:20.9
ARG RAILWAY_ENVIRONMENT
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
ENV REACT_APP_ENV=production
RUN npm run build
RUN npm prune --production
EXPOSE 80
CMD ["npm", "run", "start"]
# Base image
FROM node:20.9
ARG RAILWAY_ENVIRONMENT
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
ENV REACT_APP_ENV=production
RUN npm run build
RUN npm prune --production
EXPOSE 80
CMD ["npm", "run", "start"]
When I deploy in prod, I'm getting these errors:
IntegrationError: Missing value for Stripe(): apiKey should be a string.
InvalidKey https://developers.google.com/maps/documentation/javascript/error-messages#invalid-key
IntegrationError: Missing value for Stripe(): apiKey should be a string.
InvalidKey https://developers.google.com/maps/documentation/javascript/error-messages#invalid-key
I have the environment variables just like I have in dev. I don't understand why it can't find any of the environment variables declared the Railway. Any help? Project ID: c7f059bc-d402-459e-afbb-0d4892a4b1a5
Railway | Help Center
Getting Your Create-React-App Running on Railway – Railway | Help C...
This is a little guide to help you get your create-react-app up and running smoothly
Solution:
power is out so I hope I didn't misspell anything doing this on my phone. ```dockerfile FROM node:20.9 ARG RAILWAY_ENVIRONMENT...
Jump to solution
7 Replies
Brody
Brody8mo ago
give me a list of all the environment variables your app needs please
bbot
bbot8mo ago
Here's what I use:
REACT_APP_API_ENDPOINT=xxx
REACT_APP_GOOGLE_MAPS_APIKEY=xxx
REACT_APP_STRIPE_APIKEY=xxx
REACT_APP_GOOGLE_ANALYTICS_ID=xxx
RAILWAY_DOCKERFILE_PATH=Dockerfile.production
REACT_APP_API_ENDPOINT=xxx
REACT_APP_GOOGLE_MAPS_APIKEY=xxx
REACT_APP_STRIPE_APIKEY=xxx
REACT_APP_GOOGLE_ANALYTICS_ID=xxx
RAILWAY_DOCKERFILE_PATH=Dockerfile.production
Brody
Brody8mo ago
cool, I'll get back to you when I'm on my computer!
bbot
bbot8mo ago
Thank you!
Solution
Brody
Brody8mo ago
power is out so I hope I didn't misspell anything doing this on my phone.
FROM node:20.9

ARG RAILWAY_ENVIRONMENT
ARG REACT_APP_API_ENDPOINT
ARG REACT_APP_GOOGLE_MAPS_APIKEY
ARG REACT_APP_STRIPE_APIKEY
ARG REACT_APP_GOOGLE_ANALYTICS_ID

ENV REACT_APP_ENV=production

WORKDIR /app

COPY package*.json ./

RUN npm ci

COPY . ./

RUN npm run build

CMD ["npm", "run", "start"]
FROM node:20.9

ARG RAILWAY_ENVIRONMENT
ARG REACT_APP_API_ENDPOINT
ARG REACT_APP_GOOGLE_MAPS_APIKEY
ARG REACT_APP_STRIPE_APIKEY
ARG REACT_APP_GOOGLE_ANALYTICS_ID

ENV REACT_APP_ENV=production

WORKDIR /app

COPY package*.json ./

RUN npm ci

COPY . ./

RUN npm run build

CMD ["npm", "run", "start"]
bbot
bbot8mo ago
Thank you! That seemed to solve the env variable errors!
Brody
Brody8mo ago
awesome
Want results from more Discord servers?
Add your server