-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cloudflare Pages Environment Variables are not set through vite.define #5170
Comments
have you tried |
I have tried this approach. For the above example: import.meta.env.GITHUB_CLIENT_ID;
// undefined
import.meta.env.__GITHUB_CLIENT_ID;
// undefined |
Hi, this is a little bit of a mixup. There are two different env vars in the game here.
this is the full cloudflare (-only) way of defining and accessing env vars.
this is the full astro (-only) way of defining and accessing env vars. Unfortunately this is not currently compatible with each other. We are currently discussing a way to fix this and merge them together inside the Astro environment (there is not much to be done for a native cloudflare function as this is out of Astros hand) |
@AirBorne04 when you say there's an Astro only and Cloudflare only method what do you mean by that? If I have env vars I want to use in an endpoint, how do I do that? This is pretty confusing since the docs state that the Vite define method is what you're supposed to use with the cf adapter. However in practice those variables when accessed through |
hi @maxcountryman, yes it is a little confusing at the moment. there are basically 2 worlds which are currently kind of existing in parallel with the Cloudflare deployments.
Therefore those two worlds are living aside each other, but i am working on the PR #5103 to enable access to the Cloudflare runtime from the Astro world. |
Unfortunately 1 doesn't seem to work at all. Other folks in Discord are reporting the same issue. |
Closing this issue now that #5103 is merged |
What version of
astro
are you using?1.5.0
Are you using an SSR adapter? If so, which one?
Cloudflare
What package manager are you using?
npm
What operating system are you using?
Mac
Describe the Bug
The Astro Cloudflare Adapter docs state that I can set Cloudflare Environment variables.
I have a local .dev.vars file containing:
I have verified that this environment variable is correctly being served through a pages function:
I have updated my
astro.config.mjs
file to containUnfortunately I see that
__GITHUB_CLIENT_ID
is alwaysundefined
.EDIT:
The vite define approach works only if I explicitly set the bash variable prior to running
npm run build
ornpm run preview
. I expected the CloudFlare adapter to derive the environment variables from the Cloudflare wrangler context.See also:
clientId
parameter not to be undefinedLink to Minimal Reproducible Example
https://github.com/udiaca/u0.vc/compare/main...gh-oauth
Participation
The text was updated successfully, but these errors were encountered: