Missing environment variables on Cloudflare workers
https://github.com/kylekz/tss-cf-workers
i've taken the
pnpm create @tanstack/start@latest starter, picked tailwind + eslint + t3env + upgraded all packages to latest. then added one server var and one client var
the main branch uses a singular env.ts as per the starter, which doesn't work when running pnpm dev as server vars don't get loaded into import.meta.env, let alone attempting to deploy this
the split-env branch has separate client and server env objects: client using import.meta.env and server using process.env (which should work due to the wrangler compatibility date)
in the server function thats called in the index route loader, the server variable access errors due to variables being invalid, so the worker crashes with a 500. i switched this to lazy load the env object, catch the error and return a fallback. then the client object fails validation and errors.
i've defined both vars in the worker dashboard under the runtime variables and secrets section, not the build section. i've also tried importing env from cloudflare:workers which results in the same issue.
in my actual app, i can't even finish a deploy as i assume the build/deploy process attempts a health check of some sort, but hits the invalid environment variables error and the deploy fails:
at this point i'm completely stumped and almost positive i'm just doing something wrong with cloudflare/wrangler4 Replies
genetic-orangeā¢5w ago
Hey did u managed to resolve this issue ?
like-goldOPā¢5w ago
nope
vicious-goldā¢2w ago
i've got a project stuck here too - deploying to cloudflare workers and can't access the AI binding either locally or deployed to cloudflare. windsurf has tried 10 different approaches with claude 4.5 and i've asked grok for advice. last answer was switch to Remix which i'd rather avoid ... hoping there is an answer or a quick patch š
stormy-goldā¢5d ago
Did you set your CLIENT ENV in the BUILD SETTINGS of the Cloudflare project?