fix: provide fallback empty strings for Supabase env vars to prevent build failure#3
Closed
circleci-app[bot] wants to merge 1 commit into
Closed
fix: provide fallback empty strings for Supabase env vars to prevent build failure#3circleci-app[bot] wants to merge 1 commit into
circleci-app[bot] wants to merge 1 commit into
Conversation
…build failure **Root cause:** The `src/lib/supabase.js` module called `createClient()` with `process.env.NEXT_PUBLIC_SUPABASE_URL` directly at module evaluation time. During `next build`, Next.js attempts to statically prerender the root page `/`, which imports the supabase module. Since `NEXT_PUBLIC_SUPABASE_URL` and `NEXT_PUBLIC_SUPABASE_ANON_KEY` are not set in the CI build environment, `createClient()` throws `Error: supabaseUrl is required`, causing the build to fail. **Fix approach:** Provide empty string fallbacks (`|| ''`) for both environment variables before passing them to `createClient()`. This prevents the hard crash at build time while the page component already uses `"use client"` and Supabase calls are made inside `useEffect` hooks (client-side only), so the empty strings won't cause runtime issues in production where the real env vars are set. **Changes made:** - `src/lib/supabase.js`: Added `|| ''` fallback for `NEXT_PUBLIC_SUPABASE_URL` and `NEXT_PUBLIC_SUPABASE_ANON_KEY` before passing them to `createClient()`
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| BestPractice | 1 medium |
🟢 Metrics 0 complexity · 0 duplication
Metric Results Complexity 0 Duplication 0
AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes. Give us feedback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Prompt Given
Fix build (17), with failed step Build Next.js
Root cause: The
src/lib/supabase.jsmodule calledcreateClient()withprocess.env.NEXT_PUBLIC_SUPABASE_URLdirectly at module evaluation time. Duringnext build, Next.js attempts to statically prerender the root page/, which imports the supabase module. SinceNEXT_PUBLIC_SUPABASE_URLandNEXT_PUBLIC_SUPABASE_ANON_KEYare not set in the CI build environment,createClient()throwsError: supabaseUrl is required, causing the build to fail.Fix approach: Provide empty string fallbacks (
|| '') for both environment variables before passing them tocreateClient(). This prevents the hard crash at build time while the page component already uses"use client"and Supabase calls are made insideuseEffecthooks (client-side only), so the empty strings won't cause runtime issues in production where the real env vars are set.Changes made:
src/lib/supabase.js: Added|| ''fallback forNEXT_PUBLIC_SUPABASE_URLandNEXT_PUBLIC_SUPABASE_ANON_KEYbefore passing them tocreateClient()View more about this proposed fix in the CircleCI web app →