Env variable prefixed with PAYLOAD_PUBLIC_ not working in production #3758
Replies: 5 comments 7 replies
-
Where do your files get built to in production? I've noticed that your project's When you build for production, I imagine you build to a Example, by default, in development you should have:
Then in production:
So in both environments, you would tell This is just a problem with how you are telling |
Beta Was this translation helpful? Give feedback.
-
@jmikrut Thanks for your message. The problem here is that I don't have any Interestingly all other env variables work ( However when using the env var Even tho I expose it with |
Beta Was this translation helpful? Give feedback.
-
@jmikrut any ideas? I'm also facing this issue. Moreover, the variables are defined on server side, I get the feeling that the values are baked-in on build and access on the container at runtime. |
Beta Was this translation helpful? Give feedback.
-
I solved this issue by adding the .env file also on production. |
Beta Was this translation helpful? Give feedback.
-
I looked into this a bit. You don't necessarily need a FROM node:18.8-alpine as base
FROM base as builder
+ ARG PAYLOAD_PUBLIC_MY_VARIABLE
WORKDIR /home/node/app
COPY package*.json ./
COPY . .
RUN npm ci
RUN npm run build
… This can then be passed to Docker Build like this: As I'm hosting on Fly.io, I use: flyctl deploy \
…
+ --build-arg PAYLOAD_PUBLIC_MY_VARIABLE=value \ Now it makes all sense to me, but would be nice to have this better documented to make the distinction between "build argument" env variables and actual runtime env variables. I generally don't use a |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the Bug
Similar issues have been reported in the past: #1654, payloadcms/plugin-cloud-storage#52 and I have followed the recommended instructions without success.
I have 2 env variables:
which I need to access in my
formatPreviewURL.ts
fileEverything works fine in development, but they output
undefined
on prod.I am using/including
dotenv
in both my files:server.ts
andpayload.config.ts
File structure:
server.ts
payload-config.ts
Payload Version
1.11.7
Beta Was this translation helpful? Give feedback.
All reactions