🐛 fix(docs): stop the Groq client from failing next build - #96
Merged
Conversation
`next build` evaluates every route module while collecting page data, so the module-scope `new ChatGroq()` in `src/lib/ai/providers.ts` threw "Groq API key not found" on any build machine without `GROQ_API_KEY`, failing the Vercel build at "Collecting page data for /api/chat". - Construct the chat and embedding models lazily, on first use, and cache them. A missing key now surfaces as a `MissingApiKeyError` at request time instead of at import time. - `/api/chat` answers 503 with that message rather than crashing when the key is absent. - Declare `GROQ_API_KEY` and `OPENAI_API_KEY` in the `build` task's `env` so turbo passes the platform environment variables through (turbo warned that it was dropping them). - Declare `@radix-ui/react-tabs`, which `components/ui/tabs.tsx` imports directly but which was only ever resolved transitively; a cold install fails to compile without it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qk1775Kp6y6mLQXosPUght
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
The failure
The Vercel build died during page-data collection:
next buildevaluates every route module while collecting page data.apps/docs/src/lib/ai/providers.tsbuilt its clients at module scope:new ChatGroq()throws whenGROQ_API_KEYis absent, so importing/api/chat— which the build does — failed on any machine without the key. Turbo also warned it was droppingGROQ_API_KEY, so even a configured Vercel project would not have passed it through.The fix
getChatModel()/getEmbeddingModel()construct on first use and cache. Nothing runs at import time, so the build no longer needs a key. A missing key raises aMissingApiKeyErrorat request time./api/chatdegrades instead of crashing — 503 with the "setGROQ_API_KEY" message when the key is absent.turbo.jsondeclaresGROQ_API_KEYandOPENAI_API_KEYin thebuildtask'senv, clearing the platform-environment-variable warning so the keys reach the build when they are set.@radix-ui/react-tabsis declared inapps/docs/package.json.src/components/ui/tabs.tsximports it directly but it was only ever resolved transitively; a cold install here failed to compile withModule not found: Can't resolve '@radix-ui/react-tabs'.Verification
GROQ_API_KEYandOPENAI_API_KEYunset, importingproviders.tsnow succeeds;getChatModel()throws only when called (MissingApiKeyError: GROQ_API_KEY is not set…). Before this change the import itself threw — exactly the build failure.bun run buildinapps/docsgets pastCollecting page datawithout touching/api/chat. (The build cannot finish in this sandbox: MDX image sizing needsi.imgur.com, which egress policy blocks, and@takumi-rs/image-responsehas no native binding here. Both are environment limits, not code.)bun run readmes:checkpasses.bun run typecheckreports the same 160 pre-existing errors before and after — no regression, and CI/Vercel skip type validation.Heads-up, not fixed here
A cold
bun installtoday resolvesfumadocs-openapi@10.10.3againstfumadocs-ui@16.15.9, and that pair does not compile:fumadocs-openapi/dist/ui/client/i18n.jsimportsuseTranslationsfromfumadocs-ui/contexts/i18n, which 16.15.9 renamed touseI18n. Neither is pinned (^10.1.3,^16.2.5) and no root lockfile is committed, so this is luck of the resolve — the deployment in the log compiled fine. Upgrading tofumadocs-openapi@11is a real migration (fumadocs-openapi/ui/clientmoves), so it is out of scope for this fix. Pinningfumadocs-uito the last version that exportsuseTranslationswould be the quick lid if it bites.🤖 Generated with Claude Code
https://claude.ai/code/session_01Qk1775Kp6y6mLQXosPUght
Generated by Claude Code