Skip to content

Fix Cosmic env vars not reaching Vercel runtime#42

Closed
xuvi7 wants to merge 2 commits into
mainfrom
fix/cosmic-env-vercel-deploy
Closed

Fix Cosmic env vars not reaching Vercel runtime#42
xuvi7 wants to merge 2 commits into
mainfrom
fix/cosmic-env-vercel-deploy

Conversation

@xuvi7

@xuvi7 xuvi7 commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

What & why

Cosmic data fails to load on the deployed site, with serverless functions throwing Missing COSMIC_BUCKET_SLUG at runtime — even though the env vars are set in both GitHub Secrets and the Vercel project.

Root cause: COSMIC_* and NEXT_PUBLIC_BEHOLD_FEED_URL were declared in the GitHub Actions job-level env: block. That block only feeds vercel build running inside the CI runner; it never reaches the deployed serverless functions. Runtime env for a vercel deploy --prebuilt comes solely from the Vercel project's Environment Variables, injected at deploy time. So the build passed (env present in the runner) while runtime functions had no Cosmic vars — and the env: block actively masked the real misconfiguration.

Changes

Applied to both preview.yaml and production.yaml:

  • Removed app secrets from the env: block, leaving only VERCEL_ORG_ID and VERCEL_PROJECT_ID (the canonical Vercel CI pattern). vercel pull is now the single source of truth, so a missing/mis-scoped var fails the build loudly instead of silently shipping a broken site.
  • Added a verification step after vercel pull that prints the pulled key names (values hidden) and hard-fails with a clear ::error:: if the Cosmic keys are absent — pinpointing whether the problem is project/token scope vs. a stale deployment.

Reviewer notes / follow-up

This change makes the failure mode observable; the actual unblock depends on what the new verification step reports:

  • If it fails ("X was NOT pulled from the Vercel project") → vercel pull isn't seeing the dashboard vars. Confirm the VERCEL_ORG_ID / VERCEL_PROJECT_ID secrets and VERCEL_TOKEN scope point to the project where the Cosmic vars are set.
  • If it passes but the site still errors → it was a stale deployment; this PR's deploy should resolve it (Vercel applies env changes only to new deployments).

🤖 Generated with Claude Code

vincent-klaviyo and others added 2 commits June 13, 2026 02:22
The COSMIC_* and NEXT_PUBLIC_BEHOLD_FEED_URL vars were declared in the
GitHub Actions job-level `env:` block. That only feeds `vercel build` in
the runner; it never reaches the deployed serverless functions, whose
runtime env comes solely from the Vercel project's Environment Variables
(injected at deploy time). The result: builds passed while functions
threw "Missing COSMIC_BUCKET_SLUG" at runtime, with the env block
masking the real misconfiguration.

Changes to both preview.yaml and production.yaml:
- Drop app secrets from the `env:` block, leaving only VERCEL_ORG_ID and
  VERCEL_PROJECT_ID (the canonical Vercel CI pattern). `vercel pull` is
  now the single source of truth, so a misconfig fails the build loudly
  instead of shipping a broken site.
- Add a post-`vercel pull` verification step that prints the pulled key
  names (values hidden) and hard-fails with a clear error if the Cosmic
  keys are absent, pinpointing whether the issue is project/token scope.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The previous check matched `KEY=` even when the value was blank, so empty
Vercel env values slipped through and then failed `next build` at module
evaluation (lib/cosmic.ts treats an empty string as missing). Assert each
Cosmic var has a non-empty value after stripping quotes/whitespace.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@xuvi7 xuvi7 closed this Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants