-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
environment variables still are not available on Cloudflare Pages SSR #6130
Comments
Hi, I understand it is a little confusing, and we would like to change this behavior, but unfortunately we can't. |
So, does that mean I have to call |
You do not need to call it every time, but you might need to create a factory function and store the client instance. |
I created a factory function
How can I get it to function properly?
|
Hi I think you only need to remove this line.
and than only use it from a function like
In case you want to cache the client instance you might want to change your factory function to something like this:
|
Thanks for advice, but it didn't work well.
But, accessing these pages which using |
Hey, I know error logging is a bit tricky on cloudflare pages can you try anything suggested here? |
dev in wrangler |
Can you put a try catch on your function and return the error? Or just add a route returning the envs? |
I was able to reproduce the error after renaming
It still did not seem to be reading the environment variables. |
Sorry, this was an error.
|
@excelsior091224 I'm having the same issue, have you been able to fix it? |
no. |
Solution is found.
|
Good solution by excelsior. I'd suggest one change
|
What version of
astro
are you using?2.0.6
Are you using an SSR adapter? If so, which one?
Cloudflare
What package manager are you using?
npm
What operating system are you using?
Linux(Raspberry Pi OS)
Describe the Bug
In my blog, I'm using microCMS with this tutorial.
In this method, the environment variables
MICROCMS_SERVICE_DOMAIN
andMICROCMS_API_KEY
are read insrc/library/microcms.ts
and used to call the API to receive blog posts.src/library/microcms.ts
Since
.env
is not available for deployment with Cloudflare Pages, these environment variables are set from the Cloudflare Pages configuration.However, when deploying in SSR mode using the Cloudflare adapter, the following error occurs at the end of the deployment and it ends in failure.
It is clear that the environment variables are not readable, since you say that there is no
serviceDomain
andapiKey
.The issue is closed in #5301 as being resolved, but it is not resolved by any stretch of the imagination.
#5234 says to define it in
vite.define
in the following way.In fact, this worked. However, shouldn't the documentation then say "To use environment variables in SSR mode, they must be defined in
vite.define
"?Otherwise, it should be modified to work the normal way (
import.meta.env
).Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-vnbnoz?file=README.md&on=stackblitzhttps://stackblitz.com/edit/github-vnbnoz?file=README.md&on=stackblitz
Participation
The text was updated successfully, but these errors were encountered: