Next.js Discord

Discord Forum

Failed production deployment - Supabase integration

Unanswered
Pomeranian posted this in #help-forum
Open in Discord
PomeranianOP
Hey! Getting my Vercel deployment to work locally using npm run dev, and builds ok but then its failing on deployment, returning the below error. My .nv variables are named NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY and my file is here:
https://github.com/ebayes/canopy/blob/main/src/components/Supabase.tsx

Any help appreciated!

Error:

Failed to compile.
./src/components/Supabase.tsx:7:3
Type error: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.
5 |
6 | const supabase = createClient(
7 | process.env.NEXT_PUBLIC_SUPABASE_URL,
| ^
8 | // process.env.NEXT_PUBLIC_SUPABASE_PRIVATE_KEY,
9 | process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
10 | );
Error: Command "npm run build" exited with 1

8 Replies

Are you sure that you have uploaded the secrets to the secrets section on github
this is where you can find the secrets section on github
https://github.com/{username}/{reponame}/settings/secrets/actions
Or set the environment variables in vercel dashboard -> project page -> settings.
the cause of this error is that process.env.NEXT_PUBLIC_SUPABASE_URL type is string | undefined (typescript doesn't know if the env var exists or not), but supabase expects string. using ! will assert it to be string; using t3-env will validate the env var at runtime and give string if the env var indeed exists
PomeranianOP
Thanks all - have uploaded the secrets to the secrets section on github and tried with and without ! but no luck. Just added env variables to GitHub and still nothing.
@Pomeranian Thanks all - have uploaded the secrets to the secrets section on github and tried with and without ! but no luck. Just added env variables to GitHub and still nothing.
Try uploading 'em to vercel if that's where your site is hosted. I also use supabase for all projects and it works fine for me.
i think you can can also add the supabase integration to auto add secrets: https://vercel.com/integrations/supabase (i believe it will work)