fix(app): declare API_URL and APP_URL in the build task env - #212
R0drig0Diaz wants to merge 1 commit into
Conversation
The app build task overrides the root `build.env`, which lists API_URL and APP_URL, with a shorter list that omits both. Turborepo hides an undeclared variable from the task, so `next.config.ts` reads `process.env.API_URL` as undefined and bakes its `http://localhost:3001` fallback into the deployment. Both are build-time inputs rather than runtime ones, so `env` is correct and `passThroughEnv` is not: `next.config.ts` republishes API_URL as NEXT_PUBLIC_API_URL, which Next inlines into the bundle. A change to API_URL therefore has to invalidate the build cache, or a cached build keeps serving the previous host. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
@R0drig0Diaz is attempting to deploy a commit to the Comp AI - PoC Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/app/turbo.json">
<violation number="1" location="apps/app/turbo.json:10">
P2: This fix re-declares the root env values by hand instead of merging them, so it stays fragile. Per the Turborepo docs, a per-package `turbo.json` array field like `env` completely replaces the root value by default; the documented way to append to the inherited list is the `$TURBO_EXTENDS$` microsyntax as the first element. Because this change hardcodes API_URL/APP_URL/NEXT_PUBLIC_API_URL (already in the root `build.env`) plus NEXT_PUBLIC_AUTH_URL, the next variable added to the root `build.env` is silently dropped from the app build again — the exact failure class this PR claims to fix. Replace the hardcoded list with `$TURBO_EXTENDS$` so future root additions propagate automatically.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
| "outputs": [".next/**", "!.next/cache/**", "!.next/dev/**"], | ||
| "env": ["NEXT_PUBLIC_API_URL", "NEXT_PUBLIC_AUTH_URL"], | ||
| "env": [ | ||
| "API_URL", |
There was a problem hiding this comment.
P2: This fix re-declares the root env values by hand instead of merging them, so it stays fragile. Per the Turborepo docs, a per-package turbo.json array field like env completely replaces the root value by default; the documented way to append to the inherited list is the $TURBO_EXTENDS$ microsyntax as the first element. Because this change hardcodes API_URL/APP_URL/NEXT_PUBLIC_API_URL (already in the root build.env) plus NEXT_PUBLIC_AUTH_URL, the next variable added to the root build.env is silently dropped from the app build again — the exact failure class this PR claims to fix. Replace the hardcoded list with $TURBO_EXTENDS$ so future root additions propagate automatically.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/app/turbo.json, line 10:
<comment>This fix re-declares the root env values by hand instead of merging them, so it stays fragile. Per the Turborepo docs, a per-package `turbo.json` array field like `env` completely replaces the root value by default; the documented way to append to the inherited list is the `$TURBO_EXTENDS$` microsyntax as the first element. Because this change hardcodes API_URL/APP_URL/NEXT_PUBLIC_API_URL (already in the root `build.env`) plus NEXT_PUBLIC_AUTH_URL, the next variable added to the root `build.env` is silently dropped from the app build again — the exact failure class this PR claims to fix. Replace the hardcoded list with `$TURBO_EXTENDS$` so future root additions propagate automatically.</comment>
<file context>
@@ -6,7 +6,12 @@
"outputs": [".next/**", "!.next/cache/**", "!.next/dev/**"],
- "env": ["NEXT_PUBLIC_API_URL", "NEXT_PUBLIC_AUTH_URL"],
+ "env": [
+ "API_URL",
+ "APP_URL",
+ "NEXT_PUBLIC_API_URL",
</file context>
The bug
apps/app/turbo.jsonoverrides the rootbuild.env, and the override drops two names the root config declares:Neither
API_URLnorAPP_URLappears inglobalPassThroughEnveither, so forapp#buildboth are invisible.next.config.tsthen does this:With
API_URLhidden it resolves to the localhost fallback, and Next inlines that into the build.apps/app/lib/env.tsreads the inlined value, soapps/app/app/api/[...path]/route.tsproxies tohttp://localhost:3001in production.How it presents
The sign-in page renders normally and every call behind it fails:
The UI shows only "Could not reach the sign-in service."
API_URLwas set correctly on the deployment the entire time, which is what makes it hard to find: nothing in the platform, the build log, or the app reports a missing variable.This is a documented failure class in this repo
docs/environment.md, under "A new variable has three homes, not two":Same mechanism, one level down: the per-package task override rather than the global list.
Why
envand notpassThroughEnvdocs/environment.mdsays "passThroughEnv, neverenv" for secrets, because a secret inenvbecomes a cache key. These two are the opposite case. They are public URLs and they are build-time inputs:API_URLis inlined into the bundle viaNEXT_PUBLIC_API_URL. If it were only inpassThroughEnv, changing the API host would not invalidate the build cache and a restored cache would keep serving the previous host.APP_URLis included for the same reason:next.config.tsreads it at build time forallowedDevOrigins.Verification
Reproduced on a live Vercel deployment, and fixed there by setting
NEXT_PUBLIC_API_URLdirectly, which works precisely because that name is declared. Before and after, same deployment:GET /api/auth/okvia the appGET /api/auth/get-sessionvia the appGET /api/trpc/sso.signInOptionsvia the app{"google":true}POST /api/auth/sign-in/socialvia the appThis PR fixes the cause, so
API_URLalone is sufficient as the docs and.env.exampleimply.🤖 Generated with Claude Code
Summary by cubic
Fixes the app build task so
API_URLandAPP_URLare no longer hidden from Turborepo, preventing the production API proxy from falling back tohttp://localhost:3001and causing 502 errors on sign-in and API calls. The per-package build task inapps/app/turbo.jsonoverrides the rootenvlist and omitted these two names, sonext.config.tssaw them as undefined and inlined the localhost fallback. Declaring them inenv(notpassThroughEnv) means build caches invalidate when these URLs change, which is required because they are inlined viaNEXT_PUBLIC_API_URL.Written for commit d1cc81f. Summary will update on new commits.