Help with stripe API keys not working when deploying app

I am deploying my application that has a stripe checkout integration (with live API keys). It works perfectly with local host but it is not working when I deploy it, it says there is no stripe API keys. import Stripe from 'stripe'; console.log('stripeapi',process.env.STRIPE_SECRET_KEY); const stripe = new Stripe(process.env.STRIPE_SECRET_KEY); The above is how I use it, and I am defining it in the railway dashboard as other environment variables are defined, Use an official Node.js runtime as the base image FROM node:16 Set the working directory in the container to /app WORKDIR /app Copy package.json and package-lock.json to the working directory COPY package*.json ./ Install any needed packages specified in package.json RUN npm install Copy the rest of the application to the working directory COPY . . RUN npm run build RUN printenv RUN echo "STRIPE_API_KEY: $STRIPE_API_KEY" CMD echo "STRIPE_API_KEY: $STRIPE_API_KEY" Make port 3000 available to the world outside this container EXPOSE 3000 Define the command to run your app using CMD which defines your runtime CMD [ "npm", "start" ] CMD ["sh", "-c", "echo 'STRIPE_API_KEY: $STRIPE_API_KEY' && npm start"] This is my docker file
Solution:
```dockerfile Use an official Node.js runtime as the base image FROM node:16 ARG DATABASE_URL...
Jump to solution
20 Replies
Percy
Percy11mo ago
Project ID: N/A
Fragly
Fragly11mo ago
I don't think service variables are available during build
Jose Ricardo
Jose RicardoOP11mo ago
Yeah that's not the problem
Fragly
Fragly11mo ago
I might be misremembering though
Jose Ricardo
Jose RicardoOP11mo ago
Problem is that when app is deployed It is not able to access stripe API keys for some reason
Jose Ricardo
Jose RicardoOP11mo ago
No description
Jose Ricardo
Jose RicardoOP11mo ago
And I do have them defined here
Fragly
Fragly11mo ago
oh, I was mentioning it since you're trying to log them during build
Jose Ricardo
Jose RicardoOP11mo ago
Yeah I realized that
Brody
Brody11mo ago
they are
Fragly
Fragly11mo ago
Oh okay
Brody
Brody11mo ago
re-send your dockerfile, but please enclose it in triple backticks
Jose Ricardo
Jose RicardoOP11mo ago
"""""" ''' Use an official Node.js runtime as the base image FROM node:16 Set the working directory in the container to /app WORKDIR /app Copy package.json and package-lock.json to the working directory COPY package*.json ./ Install any needed packages specified in package.json RUN npm install Copy the rest of the application to the working directory COPY . . RUN npm run build CMD ["npm", "start"] '''
Brody
Brody11mo ago
backticks please
Jose Ricardo
Jose RicardoOP11mo ago
# Use an official Node.js runtime as the base image
FROM node:16

# Set the working directory in the container to /app
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install any needed packages specified in package.json
RUN npm install

# Copy the rest of the application to the working directory
COPY . .

RUN npm run build

CMD ["npm", "start"]
# Use an official Node.js runtime as the base image
FROM node:16

# Set the working directory in the container to /app
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install any needed packages specified in package.json
RUN npm install

# Copy the rest of the application to the working directory
COPY . .

RUN npm run build

CMD ["npm", "start"]
Brody
Brody11mo ago
can you list all the environment variables you need during build?
Jose Ricardo
Jose RicardoOP11mo ago
DATABASE_URL NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY STRIPE_SECRET_KEY
Solution
Brody
Brody11mo ago
# Use an official Node.js runtime as the base image
FROM node:16

ARG DATABASE_URL
ARG NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
ARG STRIPE_SECRET_KEY

# Set the working directory in the container to /app
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install any needed packages specified in package.json
RUN npm install

# Copy the rest of the application to the working directory
COPY . .

RUN npm run build

CMD ["npm", "start"]
# Use an official Node.js runtime as the base image
FROM node:16

ARG DATABASE_URL
ARG NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
ARG STRIPE_SECRET_KEY

# Set the working directory in the container to /app
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install any needed packages specified in package.json
RUN npm install

# Copy the rest of the application to the working directory
COPY . .

RUN npm run build

CMD ["npm", "start"]
Jose Ricardo
Jose RicardoOP11mo ago
Thank you Brody You're the goat
Brody
Brody11mo ago
no problem!
Want results from more Discord servers?
Add your server