Why would `process.env.EXAMPLE` be

Why would process.env.EXAMPLE be undefined in vite.config.ts only in cloudflare pages? It works locally, if I export EXAMPLE=hello and build, I can see hello in vite.config.ts. But in the Cloudflare Pages build, it's undefined. Would anyone know whats going on there 🤔️🙏🏼️
7 Replies
Ben-xD
Ben-xD9mo ago
Ohh,
process.env. doesn't exist in Cloudflare workers
I just need to use it directly, like EXAMPLE. Unconventional
kian
kian9mo ago
I don’t see how it’d exist directly either The build environment is a Ubuntu container, that runs Node Workers and Functions runtime aren’t Node, they’re a custom runtime, and variables are provided to the fetch handler
Ben-xD
Ben-xD9mo ago
Oh, I guess it wouldn't work Im just trying to get my environment variables in the build process, which for me is node 21. So I'm still not sure why process.env.EXAMPLE is undefined
kian
kian9mo ago
Do you see the default ones, like CF_PAGES_BRANCH?
Ben-xD
Ben-xD9mo ago
Nope, that's undefined too. I ran:
console.error(`process.env.CF_PAGES_BRANCH: ${process.env.CF_PAGES_BRANCH}`);
console.error(`CF_PAGES_BRANCH: ${CF_PAGES_BRANCH}`);
console.error(`process.env.CF_PAGES_BRANCH: ${process.env.CF_PAGES_BRANCH}`);
console.error(`CF_PAGES_BRANCH: ${CF_PAGES_BRANCH}`);
Which gives me:
process.env.CF_PAGES_BRANCH: undefined
ReferenceError: CF_PAGES_BRANCH is not defined
process.env.CF_PAGES_BRANCH: undefined
ReferenceError: CF_PAGES_BRANCH is not defined
ahh it might be my use of turbo 🥹 I think i've found a bug in turbo... This doesn't work:
"env": ["SENTRY_AUTH_TOKEN"],
"env": ["SENTRY_AUTH_TOKEN"],
I need to put it in
"globalEnv": ["SENTRY_AUTH_TOKEN"],
"globalEnv": ["SENTRY_AUTH_TOKEN"],
Yea, that's fixed it :), thanks for your replies
JustinNoel
JustinNoel9mo ago
Are you using Hono? If so, see how I add env variables here (on hono discord) https://discord.com/channels/1011308539819597844/1012485912409690122/1181284862683009094
Ben-xD
Ben-xD9mo ago
Nope I use tRPC running on Node (not on cloudflare workers). I only have a cloudflare pages frontend running on cloudflare pages I'll still take a look, thanks for the link
Want results from more Discord servers?
Add your server