Hi!
According to this documentation, I expect some environment variables (such as VERCEL_URL
) to exist and be available in my code.
However, I whenever I try to access those using i.e. import { PUBLIC_VERCEL_URL } from '$env/dynamic/public'
, I only get undefined
.
I added the PUBLIC_
prefix because this section of the doc said that prefixes are added depending on the framework chosen for the project, and I chose SvelteKit.
Although the doc only mentions outdated SvelteKit v0 (I use v2), the next paragraph do mention the correct SvelteKit prefix for such environment variables (PUBLIC_
), so I thought everything should work.
When trying to understand what was wrong, I was advised by the Svelte community to display all the environment variables to see if there was some kind of typo. I was surprised to see (when writing the content of import { env } from '$env/dynamic/public'
in the browser console) that there was no variables created by Vercel.
The solution is indeed in the SvelteKit doc when looking at the Vercel page.
But it looks like it’s the opposite of what’s in the Vercel doc. And, to be frank, I would rather have a solution similar to what’s explained in the Vercel doc.
So, my question is: what is the correct way to access the env vars automatically created by Vercel?
Is it normal that the Vercel doc is wrong (maybe it’s outdated) or is there currently an issue (meaning that I should expect to have vars such as PUBLIC_VERCEL_URL
)?
Is the solution provided in the SvelteKit doc a “workaround”, or is it the correct way to do things from now on?
I hope I’m clear, I must admit I’m a bit confused