I have a run time environment variable MY_ENV
, which I have setup locally and create in my cicd pipeline also.
I access this environment variable in my svelte app, using $env/dynamic/private
, locally it works fine. But when deployed into vercel, the environment variable is shown as undefined.
/** +layout.server.js */import { env } from '$env/dynamic/private';/** @type {import('./$types').LayoutServerLoad} */export async function load() { let my_env = env.MY_ENV; let my_region = env.MY_REGOIN; let BASE_SARAL_API_URL = 'api.saral.club/api/v1'; let url = env.LOCAL ? 'http://localhost:8000/api/v1' : `https://${my_env}-${BASE_SARAL_API_URL}`; return { BASE_SARAL_API_URL: BASE_SARAL_API_URL, URL: url, MY_ENV: my_env, MY_REGION: my_region };}
<script>/** someCompnent.svelte */export let data</script>....
In my cicd config yml file, I am using circle-ci
. I run the following sets of command:
... vercel pull --yes enviornment=preview --token=$VERCEL_TOKEN vercel build --token=$VERCEL_TOKEN vercel deploy --prebuilt --token=$VERCEL_TOKEN......
I tried with using --build-env
option but it didn't work. I passed it as follows:
... vercel deploy --build-env MY_ENV=$MY_ENV --token=$VERCEL_TOKEN...
I also tried, by setting up the environment variable in the vercel UI and making sure I run the pull step before, but that was also unsuccessful.
Basically, I am looking for help on how to pass my cicd environment variables such that they are available in vercel functions and it is able to render successfully.