What I expected to happen
I’m trying to use gcloud command line to deploy and sveltekit web app with supabase. I expected the build to complete successfully and be able to host my app on google cloud.
I have run the following command to deploy gcloud run deploy --update-env-vars SUPABASE_URL=,SUPABASE_ANON_KEY=<supabase_anon_key>
Here a link to my repo https://github.com/ming-060211/DeploymentError
What happened instead The docker build is failing at the stage “npm run build” with the following error,
Step 6/15 : RUN npm run build
---> Running in 9ea98b1abb71
> trytodaydocker@0.0.1 build
> vite build
vite v5.1.3 building SSR bundle for production...
transforming...
✓ 82 modules transformed.
rendering chunks...
THis is supaurl undefined
node:internal/event_target:1062
process.nextTick(() => { throw err; });
^
Error: supabaseUrl is required.
at new SupabaseClient (/app/node_modules/@supabase/supabase-js/dist/main/SupabaseClient.js:43:19)
at createClient (/app/node_modules/@supabase/supabase-js/dist/main/index.js:35:12)
at file:///app/.svelte-kit/output/server/entries/pages/_page.server.js:7:18
at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:336:24)
at async Promise.all (index 2)
at async analyse (file:///app/node_modules/@sveltejs/kit/src/core/postbuild/analyse.js:66:16)
at async MessagePort.<anonymous> (file:///app/node_modules/@sveltejs/kit/src/utils/fork.js:22:16)
Emitted 'error' event on Worker instance at:
at [kOnErrorMessage] (node:internal/worker:314:10)
at [kOnMessage] (node:internal/worker:325:37)
at MessagePort.<anonymous> (node:internal/worker:225:57)
at [nodejs.internal.kHybridDispatch] (node:internal/event_target:786:20)
at exports.emitMessage (node:internal/per_context/messageport:23:28)
Node.js v18.19.1
The command '/bin/sh -c npm run build' returned a non-zero code: 1
What I’ve tried to do to fix it I added the env variable to the gcloud run deploy with –update-env-vars url=asdfasdf and I printed the env var to a test page. This works so the env var is available when the app is running.
I’ve also hardcoded the supabase url and anon key, and the deployment works, but I can’t do this with production code.
What I think might be wrong The npm run build is failing because gcloud run deploy makes the env vars available during run time but they are not available during the docker build. For some reason supabase needs these vars during build and it’s failing.